From b813da5c260cde72d58f6d0e573834cb73a6cd72 Mon Sep 17 00:00:00 2001 From: delu Date: Wed, 20 Apr 2022 19:12:29 +0800 Subject: [PATCH] fix: listern use port --- Makefile | 4 ++-- build/images/controller/Dockerfile | 2 +- cmd/controller/main.go | 2 +- deploy/yaml/controller.yaml | 36 ++++++++++++++++++++---------- internal/primitive/config.go | 4 +++- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 8eeaa83c6..b16f0b8b8 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ GOOS ?= linux GOARCH ?= amd64 GO_BUILD= GO111MODULE=on CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -trimpath -DOCKER_BUILD_ARG= --build-arg=TARGETARCH=$(GOARCH) --build-arg=TARGETOS=$(GOOS) +DOCKER_BUILD_ARG= --build-arg TARGETARCH=$(GOARCH) --build-arg TARGETOS=$(GOOS) clean : rm -rf bin @@ -51,7 +51,7 @@ controller-start: build-ctrl-bin: $(GO_BUILD) -o bin/ctrl cmd/controller/eventbus/main.go -controller-start: check-module-env +controller-start: go run ${VANUS_ROOT}/cmd/controller/${module}/main.go controller-api-test: diff --git a/build/images/controller/Dockerfile b/build/images/controller/Dockerfile index 6f5f3d70a..d3977fdad 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 alpine:3.15.4 +FROM centos:8.4.2105 RUN mkdir -p /server COPY --from=builder /workspace/vanus/bin/controller /server/bin/controller WORKDIR /server diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 81e5373d6..aadf11cb5 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -75,7 +75,7 @@ func main() { os.Exit(-1) } - listen, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.IP, cfg.Port)) + listen, err := net.Listen("tcp", fmt.Sprintf("%d", cfg.Port)) if err != nil { log.Error(ctx, "failed to listen", map[string]interface{}{ "error": err, diff --git a/deploy/yaml/controller.yaml b/deploy/yaml/controller.yaml index d017b550f..d27cff882 100644 --- a/deploy/yaml/controller.yaml +++ b/deploy/yaml/controller.yaml @@ -18,26 +18,30 @@ metadata: namespace: vanus data: controller.yaml: |- - name: "test-1" - ip: "127.0.0.1" + name: ${POD_NAME} + ip: ${POD_IP} port: 2049 etcd: - - "127.0.0.1:2379" - data_dir: "/data/vanus" - topology: - service_a: "127.0.0.1:2049" + - "vanus-controller-0.vanus-controller.vanus.svc.cluster.local:2379" + - "vanus-controller-1.vanus-controller.vanus.svc.cluster.local:2379" + - "vanus-controller-2.vanus-controller.vanus.svc.cluster.local:2379" + data_dir: "/data" metadata: - key_prefix: "/wenfeng" + key_prefix: "/vanus" embed_etcd: - name: "etcd-1" - data_dir: "etcd/node1" + name: ${POD_NAME} + # relative path to ${data_dir} above + data_dir: "etcd/data" client_addr: "127.0.0.1:2379" peer_addr: "127.0.0.1:2380" clusters: - - "etcd-1=http://127.0.0.1:2380" + - vanus-controller-0=http://vanus-controller-0.vanus-controller.vanus.svc.cluster.local:2380 + - vanus-controller-1=http://vanus-controller-1.vanus-controller.vanus.svc.cluster.local:2380 + - vanus-controller-2=http://vanus-controller-2.vanus-controller.vanus.svc.cluster.local:2380 + #eventbus: trigger: storage: - keyPrefix: "/xdl" + keyPrefix: "/vanus" serverList: [ "127.0.0.1:2379" ] --- @@ -54,7 +58,6 @@ spec: clusterIP: None ports: - port: 2049 - targetPort: 2049 name: vanus-controller --- apiVersion: apps/v1 @@ -100,6 +103,15 @@ spec: containerPort: 2379 - name: etcd-peer containerPort: 2380 + env: + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: POD_ID + valueFrom: + fieldRef: + fieldPath: status.podIP volumeMounts: - name: config-controller mountPath: /server/config diff --git a/internal/primitive/config.go b/internal/primitive/config.go index d19215d54..e0b93aebe 100644 --- a/internal/primitive/config.go +++ b/internal/primitive/config.go @@ -17,6 +17,7 @@ package primitive import ( "gopkg.in/yaml.v3" "io/ioutil" + "os" ) type StorageKeyPrefix string @@ -41,7 +42,8 @@ func LoadConfig(filename string, config interface{}) error { if err != nil { return err } - err = yaml.Unmarshal(b, config) + str := os.ExpandEnv(string(b)) + err = yaml.Unmarshal([]byte(str), config) if err != nil { return err }