diff --git a/Makefile b/Makefile index 3af07c626..8eeaa83c6 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ VSPROTO_ROOT=$(VANUS_ROOT)/../vsproto export VANUS_LOG_LEVEL=debug -DOCKER_REGISTRY ?= linkall.cloud -DOCKER_REPO ?= ${DOCKER_REGISTRY}/vanus +DOCKER_REGISTRY ?= public.ecr.aws +DOCKER_REPO ?= ${DOCKER_REGISTRY}/t8a4l2d7 IMAGE_TAG ?= latest #os linux or darwin GOOS ?= linux diff --git a/build/images/controller/Dockerfile b/build/images/controller/Dockerfile index d3977fdad..6f5f3d70a 100644 --- a/build/images/controller/Dockerfile +++ b/build/images/controller/Dockerfile @@ -10,7 +10,7 @@ ARG TARGETOS ARG TARGETARCH RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-controller -FROM centos:8.4.2105 +FROM alpine:3.15.4 RUN mkdir -p /server COPY --from=builder /workspace/vanus/bin/controller /server/bin/controller WORKDIR /server diff --git a/build/images/gateway/Dockerfile b/build/images/gateway/Dockerfile index fd73595c9..d9006f7e5 100644 --- a/build/images/gateway/Dockerfile +++ b/build/images/gateway/Dockerfile @@ -10,7 +10,7 @@ ARG TARGETOS ARG TARGETARCH RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-gateway -FROM centos:8.4.2105 +FROM alpine:3.15.4 RUN mkdir -p /server COPY --from=builder /workspace/vanus/bin/gateway /server/bin/gateway WORKDIR /server diff --git a/build/images/store/Dockerfile b/build/images/store/Dockerfile index 0f708f72d..48bcfb9f4 100644 --- a/build/images/store/Dockerfile +++ b/build/images/store/Dockerfile @@ -10,7 +10,7 @@ ARG TARGETOS ARG TARGETARCH RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-store -FROM centos:8.4.2105 +FROM alpine:3.15.4 RUN mkdir -p /server COPY --from=builder /workspace/vanus/bin/store /server/bin/store WORKDIR /server diff --git a/build/images/trigger/Dockerfile b/build/images/trigger/Dockerfile index 529211042..1e167be4d 100644 --- a/build/images/trigger/Dockerfile +++ b/build/images/trigger/Dockerfile @@ -10,7 +10,7 @@ ARG TARGETOS ARG TARGETARCH RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-trigger -FROM centos:8.4.2105 +FROM alpine:3.15.4 RUN mkdir -p /server COPY --from=builder /workspace/vanus/bin/trigger /server/bin/trigger WORKDIR /server diff --git a/cmd/store/main.go b/cmd/store/main.go index e9951bdc9..ccabe4bfa 100644 --- a/cmd/store/main.go +++ b/cmd/store/main.go @@ -20,12 +20,8 @@ import ( "flag" "fmt" "github.com/linkall-labs/vanus/internal/store" - "gopkg.in/yaml.v3" - "io" "net" "os" - "time" - // third-party libraries. "google.golang.org/grpc" @@ -37,53 +33,18 @@ import ( "github.com/linkall-labs/vanus/internal/primitive" "github.com/linkall-labs/vanus/internal/raft/transport" "github.com/linkall-labs/vanus/internal/store/segment" - "github.com/linkall-labs/vanus/internal/util" "github.com/linkall-labs/vanus/observability/log" ) -<<<<<<< HEAD func main() { f := flag.String("config", "./config/gateway.yaml", "gateway config file path") flag.Parse() - cfg, err := segment.Init(*f) + cfg, err := store.InitConfig(*f) if err != nil { log.Error(nil, "init config error", map[string]interface{}{log.KeyError: err}) os.Exit(-1) } listen, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.Port)) -======= -var ( - configPath = flag.String("config-file", "./config/store.yaml", "the configuration file of controller") -) - -func main() { - flag.Parse() - - f, err := os.Open(*configPath) - if err != nil { - log.Error(nil, "open configuration file failed", map[string]interface{}{ - log.KeyError: err, - }) - os.Exit(-1) - } - data, err := io.ReadAll(f) - if err != nil { - log.Error(nil, "read configuration file failed", map[string]interface{}{ - log.KeyError: err, - }) - os.Exit(-1) - } - - cfg := store.Config{} - if err = yaml.Unmarshal(data, &cfg); err != nil { - log.Error(nil, "unmarshall configuration file failed", map[string]interface{}{ - log.KeyError: err, - }) - os.Exit(-1) - } - - listen, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.IP, cfg.Port)) ->>>>>>> 14516ae (feat: add store.Config) if err != nil { log.Error(context.Background(), "failed to listen", map[string]interface{}{ "error": err, @@ -104,13 +65,7 @@ func main() { host := transport.NewHost(reslover) raftSrv := transport.NewRaftServer(context.TODO(), host) raftpb.RegisterRaftServerServer(grpcServer, raftSrv) - -<<<<<<< HEAD - srv := segment.NewSegmentServer(fmt.Sprintf("%s:%d", util.LocalIp, cfg.Port), cfg.ControllerAddr, - uint64(1), stopCallback) -======= - srv := segment.NewSegmentServer(cfg, stopCallback) ->>>>>>> 14516ae (feat: add store.Config) + srv := segment.NewSegmentServer(*cfg, stopCallback) if err != nil { stopCallback() log.Error(context.Background(), "start SegmentServer failed", map[string]interface{}{ @@ -133,13 +88,8 @@ func main() { go func() { log.Info(ctx, "the SegmentServer ready to work", map[string]interface{}{ -<<<<<<< HEAD - "time": util.FormatTime(time.Now()), -======= "listen_ip": cfg.IP, "listen_port": cfg.Port, - "time": util.FormatTime(time.Now()), ->>>>>>> 14516ae (feat: add store.Config) }) if err = grpcServer.Serve(listen); err != nil { log.Error(ctx, "grpc server occurred an error", map[string]interface{}{ diff --git a/cmd/trigger/main.go b/cmd/trigger/main.go index d3c152562..a30d1209f 100644 --- a/cmd/trigger/main.go +++ b/cmd/trigger/main.go @@ -33,7 +33,7 @@ func main() { ctx := signal.SetupSignalContext() f := flag.String("config", "./config/trigger.yaml", "trigger worker config file path") flag.Parse() - c, err := trigger.Init(*f) + c, err := trigger.InitConfig(*f) if err != nil { log.Error(nil, "init config error", map[string]interface{}{log.KeyError: err}) os.Exit(-1) diff --git a/config/trigger.yaml b/config/trigger.yaml index e759be130..93de3ae7b 100644 --- a/config/trigger.yaml +++ b/config/trigger.yaml @@ -1,2 +1,2 @@ port: 2149 -controller_addr: "127.0.0.1:2048" \ No newline at end of file +controller: ["127.0.0.1:2048"] \ No newline at end of file diff --git a/deploy/yaml/controller.yaml b/deploy/yaml/controller.yaml index 98a0819dd..d017b550f 100644 --- a/deploy/yaml/controller.yaml +++ b/deploy/yaml/controller.yaml @@ -17,13 +17,35 @@ metadata: name: config-controller namespace: vanus data: - port: 2049 + controller.yaml: |- + name: "test-1" + ip: "127.0.0.1" + port: 2049 + etcd: + - "127.0.0.1:2379" + data_dir: "/data/vanus" + topology: + service_a: "127.0.0.1:2049" + metadata: + key_prefix: "/wenfeng" + embed_etcd: + name: "etcd-1" + data_dir: "etcd/node1" + client_addr: "127.0.0.1:2379" + peer_addr: "127.0.0.1:2380" + clusters: + - "etcd-1=http://127.0.0.1:2380" + trigger: + storage: + keyPrefix: "/xdl" + serverList: [ "127.0.0.1:2379" ] --- apiVersion: v1 kind: Service metadata: name: vanus-controller + namespace: vanus labels: app: vanus-controller spec: @@ -36,25 +58,37 @@ spec: name: vanus-controller --- apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: name: vanus-controller namespace: vanus labels: - app.kubernetes.io/name: vanus-controller + app: vanus-controller spec: selector: matchLabels: app: vanus-controller + replicas: 3 + serviceName: vanus-controller + volumeClaimTemplates: + - metadata: + name: data + labels: + app: vanus-controller + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi template: metadata: labels: app: vanus-controller - app.kubernetes.io/name: vanus-controller spec: containers: - name: controller - image: linkall.cloud/vanus/controller:latest + image: public.ecr.aws/t8a4l2d7/controller:latest resources: requests: cpu: 100m @@ -62,10 +96,15 @@ spec: ports: - name: grpc containerPort: 2049 + - name: etcd-client + containerPort: 2379 + - name: etcd-peer + containerPort: 2380 volumeMounts: - name: config-controller - mountPath: /server/config/controller.yaml - subPath: controller.yaml + mountPath: /server/config + - name: data + mountPath: /data volumes: - name: config-controller configMap: diff --git a/deploy/yaml/gateway.yaml b/deploy/yaml/gateway.yaml index 4d9a0483b..97becf1dc 100644 --- a/deploy/yaml/gateway.yaml +++ b/deploy/yaml/gateway.yaml @@ -33,8 +33,9 @@ metadata: name: config-gateway namespace: vanus data: - port: 8080 - controller_addr: "127.0.0.1:2049" + gateway.yaml: |- + port: 8080 + controller_addr: "127.0.0.1:2049" --- apiVersion: apps/v1 @@ -66,8 +67,7 @@ spec: containerPort: 8080 volumeMounts: - name: config-gateway - mountPath: /server/config/gateway.yaml - subPath: gateway.yaml + mountPath: /server/config volumes: - name: config-gateway configMap: diff --git a/deploy/yaml/store.yaml b/deploy/yaml/store.yaml index 27bfb7593..72fe1038a 100644 --- a/deploy/yaml/store.yaml +++ b/deploy/yaml/store.yaml @@ -32,8 +32,9 @@ metadata: name: config-store namespace: vanus data: - port: 11811 - controller_addr: "127.0.0.1:2049" + store.yaml: |- + port: 11811 + controller_addr: "127.0.0.1:2049" --- apiVersion: apps/v1 @@ -65,8 +66,7 @@ spec: containerPort: 11811 volumeMounts: - name: config-store - mountPath: /server/config/store.yaml - subPath: store.yaml + mountPath: /server/config volumes: - name: config-store configMap: diff --git a/deploy/yaml/trigger.yaml b/deploy/yaml/trigger.yaml index 6e65bf19a..1800e01d9 100644 --- a/deploy/yaml/trigger.yaml +++ b/deploy/yaml/trigger.yaml @@ -17,8 +17,12 @@ metadata: name: config-trigger namespace: vanus data: - port: 2149 - controller_addr: "127.0.0.1:2049" + trigger.yaml: |- + port: 2149 + controller: + - "vanus-controller-0.vanus-controller.vanus.svc.cluster.local:2049" + - "vanus-controller-1.vanus-controller.vanus.svc.cluster.local:2049" + - "vanus-controller-2.vanus-controller.vanus.svc.cluster.local:2049" --- apiVersion: apps/v1 @@ -40,7 +44,8 @@ spec: spec: containers: - name: trigger - image: linkall.com/vanus/trigger:latest + image: public.ecr.aws/t8a4l2d7/trigger:latest + imagePullPolicy: Always resources: requests: cpu: 100m @@ -50,8 +55,7 @@ spec: containerPort: 2149 volumeMounts: - name: config-trigger - mountPath: /server/config/trigger.yaml - subPath: trigger.yaml + mountPath: /server/config volumes: - name: config-trigger configMap: diff --git a/internal/store/config.go b/internal/store/config.go index 9ca4d84da..0db372988 100644 --- a/internal/store/config.go +++ b/internal/store/config.go @@ -14,7 +14,10 @@ package store -import "github.com/linkall-labs/vanus/internal/primitive/vanus" +import ( + "github.com/linkall-labs/vanus/internal/primitive" + "github.com/linkall-labs/vanus/internal/primitive/vanus" +) type Config struct { ControllerAddresses []string `json:"controllers"` @@ -28,3 +31,12 @@ type VolumeInfo struct { Dir string `json:"dir"` Capacity uint64 `json:"capacity"` } + +func InitConfig(filename string) (*Config, error) { + c := new(Config) + err := primitive.LoadConfig(filename, c) + if err != nil { + return nil, err + } + return c, nil +} diff --git a/internal/store/segment/config.go b/internal/store/segment/config.go deleted file mode 100644 index 7a213ca23..000000000 --- a/internal/store/segment/config.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2022 Linkall Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package segment - -import ( - "github.com/linkall-labs/vanus/internal/primitive" -) - -type Config struct { - Port int `yaml:"port"` - ControllerAddr string `yaml:"controller_addr"` -} - -func Init(filename string) (*Config, error) { - c := new(Config) - err := primitive.LoadConfig(filename, c) - if err != nil { - return nil, err - } - return c, nil -} diff --git a/internal/trigger/config.go b/internal/trigger/config.go index 48c5d996d..d686442a7 100644 --- a/internal/trigger/config.go +++ b/internal/trigger/config.go @@ -19,12 +19,12 @@ import ( ) type Config struct { - Port int `yaml:"port"` - ControllerAddr string `yaml:"controller_addr"` + Port int `yaml:"port"` + ControllerAddr []string `yaml:"controller"` TriggerAddr string } -func Init(filename string) (*Config, error) { +func InitConfig(filename string) (*Config, error) { c := new(Config) err := primitive.LoadConfig(filename, c) if err != nil { diff --git a/internal/trigger/server.go b/internal/trigger/server.go index 9ed2c73e9..9d0431d5c 100644 --- a/internal/trigger/server.go +++ b/internal/trigger/server.go @@ -136,7 +136,7 @@ func (s *server) init(ctx context.Context) error { opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) timeout, cancel := context.WithTimeout(ctx, time.Second*10) defer cancel() - cc, err := grpc.DialContext(timeout, s.config.ControllerAddr, opts...) + cc, err := grpc.DialContext(timeout, s.config.ControllerAddr[0], opts...) if err != nil { return err }