Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement raft storage node #3

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.dll
*.so
*.dylib

**/_output
# Test binary, build with `go test -c`
*.test

Expand Down
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: false
language: go

go:
- '1.12.x'
- '1.13.x'

notifications:
email: false
Expand All @@ -26,16 +26,10 @@ install:
before_script:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest

after_success:
- if [[ "$TRAVIS_BRANCH" == "master" ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD;
make push;
fi

jobs:
include:
- stage: tests
script:
- make coverage
- goveralls -coverprofile=coverage.out -service=travis-ci
- make image
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./build/bin/push-images; fi'
28 changes: 16 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,43 @@ export GO111MODULE=on

.PHONY: build

ATOMIX_RAFT_NODE_VERSION := latest
ATOMIX_RAFT_STORAGE_VERSION := latest

all: build

build: # @HELP build the source code
build:
GOOS=linux GOARCH=amd64 go build -o build/_output/atomix-raft-node ./cmd/atomix-raft-node
build: deps
GOOS=linux GOARCH=amd64 go build -o build/raft-storage-node/_output/raft-storage-node ./cmd/raft-storage-node


deps: # @HELP ensure that the required dependencies are in place
go build -v ./...

test: # @HELP run the unit tests and source code validation
test: build license_check linters
go test github.com/atomix/raft-replica/...
#go test github.com/atomix/raft-storage/...

coverage: # @HELP generate unit test coverage data
coverage: build linters license_check
go test github.com/atomix/raft-replica/pkg/... -coverprofile=coverage.out.tmp -covermode=count
@cat coverage.out.tmp | grep -v ".pb.go" > coverage.out
#go test github.com/atomix/raft-storage/pkg/... -coverprofile=coverage.out.tmp -covermode=count
#@cat coverage.out.tmp | grep -v ".pb.go" > coverage.out

linters: # @HELP examines Go source code and reports coding problems
golangci-lint run
GOGC=50 golangci-lint run

license_check: # @HELP examine and ensure license headers exist
./build/licensing/boilerplate.py -v

proto: # @HELP build Protobuf/gRPC generated types
proto:
docker run -it -v `pwd`:/go/src/github.com/atomix/raft-replica \
-w /go/src/github.com/atomix/raft-replica \
docker run -it -v `pwd`:/go/src/github.com/atomix/raft-storage \
-w /go/src/github.com/atomix/raft-storage \
--entrypoint build/bin/compile_protos.sh \
onosproject/protoc-go:stable

image: # @HELP build atomix-raft-node Docker image
image: # @HELP build atomix storage and atomix storage controller Docker images
image: build
docker build . -f build/docker/Dockerfile -t atomix/raft-replica:${ATOMIX_RAFT_NODE_VERSION}
docker build . -f build/raft-storage-node/Dockerfile -t atomix/raft-storage-node:${ATOMIX_RAFT_STORAGE_VERSION}

push: # @HELP push atomix-raft-node Docker image
docker push atomix/raft-replica:${ATOMIX_RAFT_NODE_VERSION}
docker push atomix/raft-storage-node:${ATOMIX_RAFT_STORAGE_VERSION}
5 changes: 5 additions & 0 deletions build/bin/push-images
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USER" --password-stdin
make image
make push

7 changes: 0 additions & 7 deletions build/docker/Dockerfile

This file was deleted.

7 changes: 7 additions & 0 deletions build/raft-storage-node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3.9

USER nobody

ADD build/raft-storage-node/_output/raft-storage-node /usr/local/bin/raft-storage-node

ENTRYPOINT ["raft-storage-node"]
23 changes: 12 additions & 11 deletions cmd/atomix-raft-node/main.go → cmd/raft-storage-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/signal"

"github.com/atomix/api/proto/atomix/controller"
"github.com/atomix/go-framework/pkg/atomix"
"github.com/atomix/go-framework/pkg/atomix/registry"
"github.com/atomix/raft-replica/pkg/atomix/raft"
"github.com/atomix/raft-replica/pkg/atomix/raft/config"
"github.com/gogo/protobuf/jsonpb"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"
"os/signal"
)

func main() {
log.SetLevel(log.TraceLevel)
log.SetOutput(os.Stdout)

nodeID := os.Args[1]
partitionConfig := parsePartitionConfig()
clusterConfig := parseClusterConfig()
protocolConfig := parseProtocolConfig()

// Start the node. The node will be started in its own goroutine.
node := atomix.NewNode(nodeID, partitionConfig, raft.NewProtocol(protocolConfig), registry.Registry)
node := atomix.NewNode(nodeID, clusterConfig, raft.NewProtocol(protocolConfig), registry.Registry)
if err := node.Start(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -56,19 +57,19 @@ func main() {
}
}

func parsePartitionConfig() *controller.PartitionConfig {
nodeConfigFile := os.Args[2]
nodeConfig := &controller.PartitionConfig{}
nodeBytes, err := ioutil.ReadFile(nodeConfigFile)
func parseClusterConfig() *controller.ClusterConfig {
clusterConfigFile := os.Args[2]
clusterConfig := &controller.ClusterConfig{}
clusterConfigBytes, err := ioutil.ReadFile(clusterConfigFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if err := jsonpb.Unmarshal(bytes.NewReader(nodeBytes), nodeConfig); err != nil {
if err := jsonpb.Unmarshal(bytes.NewReader(clusterConfigBytes), clusterConfig); err != nil {
fmt.Println(err)
os.Exit(1)
}
return nodeConfig
return clusterConfig
}

func parseProtocolConfig() *config.ProtocolConfig {
Expand Down
26 changes: 26 additions & 0 deletions deploy/examples/raft-storage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: storage.cloud.atomix.io/v1beta1
kind: RaftStorageClass
metadata:
name: raft
labels:
app: raft
spec:
image: atomix/raft-storage-node:latest
imagePullPolicy: IfNotPresent
replicas: 1
---
apiVersion: cloud.atomix.io/v1beta2
kind: Database
metadata:
name: raft
spec:
clusters: 3
template:
spec:
partitions: 10
storage:
group: storage.cloud.atomix.io
version: v1beta1
kind: RaftStorageClass
name: raft
namespace: kube-system
15 changes: 15 additions & 0 deletions deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
name: raft-database
description: raft database
kubeVersion: ">=1.12.0"
type: application
version: 0.1.0
appVersion: v0.1.0-beta.1
keywords:
- atomix
home: https://atomix.io
maintainers:
- name: adib
email: [email protected]
- name: kuujo
email: [email protected]
63 changes: 63 additions & 0 deletions deploy/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "cache-storage.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "cache-storage.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "cache-storage.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "cache-storage.labels" -}}
helm.sh/chart: {{ include "cache-storage.chart" . }}
{{ include "cache-storage.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "cache-storage.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cache-storage.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "cache-storage.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "cache-storage.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
15 changes: 15 additions & 0 deletions deploy/helm/templates/database.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: cloud.atomix.io/v1beta2
kind: Database
metadata:
name: {{ .Release.Name }}
spec:
clusters: {{ .Values.clusters }}
template:
spec:
partitions: {{ .Values.partitions }}
storage:
group: storage.cloud.atomix.io
version: v1beta1
kind: RaftStorageClass
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
10 changes: 10 additions & 0 deletions deploy/helm/templates/storage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: storage.cloud.atomix.io/v1beta1
kind: RaftStorageClass
metadata:
name: {{ .Release.Name }}
labels:
app: {{ .Release.Name }}
spec:
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
replicas: {{ .Values.replicas }}
9 changes: 9 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
clusters: 3
partitions: 10
replicas: 1

image:
repository: atomix/raft-storage-node
tag: latest
pullPolicy: IfNotPresent
pullSecrets: []
Loading