From 2d858194dfa486f8793ef7cddb137be0000c6f54 Mon Sep 17 00:00:00 2001 From: doyoubi Date: Sun, 15 Nov 2020 17:59:43 +0800 Subject: [PATCH 1/2] Fix operator and crd can't be deployed in different namespace --- README.md | 12 +++++++----- config/manager/bases/manager.yaml | 4 ++++ controllers/broker.go | 2 +- controllers/meta.go | 11 +++++++++-- helm/undermoon-cluster/values.yaml | 10 +++++----- helm/undermoon-operator/templates/operator.yaml | 4 ++++ 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index cd41133..3680a7b 100644 --- a/README.md +++ b/README.md @@ -11,25 +11,27 @@ using [operator-sdk](https://sdk.operatorframework.io/). ``` Then you can see the following packages in the current directory: -- undermoon-operator-0.1.1.tgz -- undermoon-cluster-0.1.1.tgz +- undermoon-operator-0.1.2.tgz +- undermoon-cluster-0.1.2.tgz ### Run the Operator Run the `undermoon-operator`: Note that you can change the name `my-undermoon-operator`. ``` -> helm install my-undermoon-operator undermoon-operator-0.1.1.tgz +> helm install my-undermoon-operator undermoon-operator-0.1.2.tgz ``` ### Create an Undermoon Cluster Create an undermoon cluster by installing helm charts package: ``` -> helm install my-cluster \ +> helm install \ --set 'cluster.clusterName=my-cluster-name' \ --set 'cluster.chunkNumber=1' \ --set 'cluster.maxMemory=50' \ --set 'cluster.port=5299' \ - undermoon-cluster-0.1.1.tgz + my-cluster \ + -n my-namespace \ + undermoon-cluster-0.1.2.tgz ``` Fields here: diff --git a/config/manager/bases/manager.yaml b/config/manager/bases/manager.yaml index f3b7420..55e67e1 100644 --- a/config/manager/bases/manager.yaml +++ b/config/manager/bases/manager.yaml @@ -46,6 +46,10 @@ spec: env: - name: GIN_MODE value: "release" + - name: UNDERMOON_OPERATOR_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace resources: limits: cpu: 100m diff --git a/controllers/broker.go b/controllers/broker.go index 6b6c0f3..cb8e680 100644 --- a/controllers/broker.go +++ b/controllers/broker.go @@ -166,7 +166,7 @@ func createBrokerStatefulSet(cr *undermoonv1alpha1.Undermoon) *appsv1.StatefulSe }, { Name: "UNDERMOON_HTTP_STORAGE_ADDRESS", - Value: fmt.Sprintf("%s:%d", metaServiceHost, metaServicePort), + Value: fmt.Sprintf("%s:%d", metaServiceHost(), metaServicePort), }, { Name: "UNDERMOON_REFRESH_INTERVAL", diff --git a/controllers/meta.go b/controllers/meta.go index 9d906ce..d4c54c7 100644 --- a/controllers/meta.go +++ b/controllers/meta.go @@ -2,6 +2,7 @@ package controllers import ( "fmt" + "os" "strings" pkgerrors "github.com/pkg/errors" @@ -16,8 +17,9 @@ const ( metaStoreKey = "broker_meta_store" metaPasswordKey = "broker_meta_password" // The service is provided by this operator. - metaServiceHost = "undermoon-operator-storage" - metaServicePort = 9999 + metaServiceName = "undermoon-operator-storage" + metaServicePort = 9999 + operatorNamespaceEnvVarName = "UNDERMOON_OPERATOR_NAMESPACE" ) func createMetaConfigMap(cr *undermoonv1alpha1.Undermoon, initData string) *corev1.ConfigMap { @@ -80,6 +82,11 @@ func brokerStorageName(undermoonName, namespace string) string { return fmt.Sprintf("%s@%s", undermoonName, namespace) } +func metaServiceHost() string { + namespace := os.Getenv(operatorNamespaceEnvVarName) + return fmt.Sprintf("%s.%s.svc.cluster.local", metaServiceName, namespace) +} + func extractStorageName(name string) (string, string, error) { segs := strings.SplitN(name, "@", 2) if len(segs) != 2 { diff --git a/helm/undermoon-cluster/values.yaml b/helm/undermoon-cluster/values.yaml index b0146a6..90aa6f8 100644 --- a/helm/undermoon-cluster/values.yaml +++ b/helm/undermoon-cluster/values.yaml @@ -12,7 +12,7 @@ cluster: image: undermoonImage: doyoubi/undermoon - undermoonImageTag: 0.4.1 + undermoonImageTag: 0.4.1-buster undermoonImagePullPolicy: IfNotPresent redisImage: redis redisImageTag: 5.0.9 @@ -21,19 +21,19 @@ resources: brokerResources: limits: {} - # cpu: "0.05" + # memory: "1G" coordinatorResources: limits: {} - # cpu: "0.05" + # memory: "1G" proxyResources: limits: {} - # cpu: "0.05" + # memory: "1G" redisResources: limits: {} - # cpu: "0.05" + # memory: "5G" nameOverride: "" fullnameOverride: "" diff --git a/helm/undermoon-operator/templates/operator.yaml b/helm/undermoon-operator/templates/operator.yaml index bec804f..96e0f82 100644 --- a/helm/undermoon-operator/templates/operator.yaml +++ b/helm/undermoon-operator/templates/operator.yaml @@ -35,6 +35,10 @@ spec: env: - name: GIN_MODE value: release + - name: UNDERMOON_OPERATOR_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace image: '{{ .Values.image.operatorImage }}:{{ .Values.image.operatorImageTag }}' imagePullPolicy: '{{ .Values.image.operatorImagePullPolicy }}' name: manager From 5b1ee9bf936e0eda88c31ee48eb05e826825b95c Mon Sep 17 00:00:00 2001 From: doyoubi Date: Sun, 15 Nov 2020 18:42:46 +0800 Subject: [PATCH 2/2] Bump operator version to v0.1.2 --- Makefile | 2 +- config/manager/overlays/test/kustomization.yaml | 2 +- helm/undermoon-operator/Chart.yaml | 2 +- helm/undermoon-operator/values.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9dd2fe7..9d1d809 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Current Operator version -VERSION ?= v0.1.1 +VERSION ?= v0.1.2 # Default bundle image tag BUNDLE_IMG ?= controller-bundle:$(VERSION) # Options for 'bundle-build' diff --git a/config/manager/overlays/test/kustomization.yaml b/config/manager/overlays/test/kustomization.yaml index fe3a85c..66ce227 100644 --- a/config/manager/overlays/test/kustomization.yaml +++ b/config/manager/overlays/test/kustomization.yaml @@ -7,7 +7,7 @@ resources: images: - name: controller newName: localhost:5000/undermoon-operator - newTag: v0.1.1 + newTag: v0.1.2 patchesJson6902: - target: diff --git a/helm/undermoon-operator/Chart.yaml b/helm/undermoon-operator/Chart.yaml index 0be856b..2b12cfa 100644 --- a/helm/undermoon-operator/Chart.yaml +++ b/helm/undermoon-operator/Chart.yaml @@ -22,4 +22,4 @@ version: 0.1.2 # follow Semantic Versioning. They should reflect the version the application is using. # # This should be the same as the version of undermoon-operator. -appVersion: v0.1.1 +appVersion: v0.1.2 diff --git a/helm/undermoon-operator/values.yaml b/helm/undermoon-operator/values.yaml index 83d2e8c..ce23569 100644 --- a/helm/undermoon-operator/values.yaml +++ b/helm/undermoon-operator/values.yaml @@ -4,7 +4,7 @@ image: operatorImage: doyoubi/undermoon-operator - operatorImageTag: v0.1.1 + operatorImageTag: v0.1.2 operatorImagePullPolicy: IfNotPresent nameOverride: ""