You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2020/09/07 16:02:50 UTC

[rocketmq-operator] branch fix_issue#45 created (now 4335d91)

This is an automated email from the ASF dual-hosted git repository.

liurui pushed a change to branch fix_issue#45
in repository https://gitbox.apache.org/repos/asf/rocketmq-operator.git.


      at 4335d91  fix(*): fix store path and auto-set nameserver ip list

This branch includes the following new commits:

     new 4335d91  fix(*): fix store path and auto-set nameserver ip list

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[rocketmq-operator] 01/01: fix(*): fix store path and auto-set nameserver ip list

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liurui pushed a commit to branch fix_issue#45
in repository https://gitbox.apache.org/repos/asf/rocketmq-operator.git

commit 4335d914308869424a1958b70b936bd421bf87a6
Author: liuruiyiyang <li...@apache.org>
AuthorDate: Tue Sep 8 00:02:00 2020 +0800

    fix(*): fix store path and auto-set nameserver ip list
---
 README.md                                       | 39 +++++++++++++++++++++----
 create-operator.sh                              |  2 +-
 deploy/operator.yaml                            |  2 +-
 example/rocketmq_v1alpha1_broker_cr.yaml        |  9 ++----
 example/rocketmq_v1alpha1_nameservice_cr.yaml   |  2 +-
 example/rocketmq_v1alpha1_rocketmq_cluster.yaml | 39 +++++++++++++++++++++----
 go.mod                                          |  4 +--
 images/broker/alpine/Dockerfile                 |  3 +-
 images/broker/alpine/build-broker-image.sh      |  5 ++--
 images/namesrv/alpine/Dockerfile                |  4 +--
 images/namesrv/alpine/build-namesrv-image.sh    |  5 ++--
 pkg/constants/constants.go                      | 15 ++++++----
 pkg/controller/broker/broker_controller.go      |  2 +-
 13 files changed, 94 insertions(+), 37 deletions(-)

diff --git a/README.md b/README.md
index ff844ef..cdd84dc 100644
--- a/README.md
+++ b/README.md
@@ -159,6 +159,22 @@ RocketMQ Operator provides several CRDs to allow users define their RocketMQ ser
 
 1. Check the file ```rocketmq_v1alpha1_rocketmq_cluster.yaml``` in the ```example``` directory, for example:
 ```
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: broker-config
+data:
+  # BROKER_MEM sets the broker JVM, if set to "" then Xms = Xmx = max(min(1/2 ram, 1024MB), min(1/4 ram, 8GB))
+  BROKER_MEM: ""
+  broker-common.conf: |
+    # brokerClusterName, brokerName, brokerId are automatically generated by the operator and do not set it manually!!!
+    deleteWhen=04
+    fileReservedTime=48
+    flushDiskType=ASYNC_FLUSH
+    # set brokerRole to ASYNC_MASTER or SYNC_MASTER. DO NOT set to SLAVE because the replica instance will automatically be set!!!
+    brokerRole=ASYNC_MASTER
+
+---
 apiVersion: rocketmq.apache.org/v1alpha1
 kind: Broker
 metadata:
@@ -169,12 +185,10 @@ spec:
   size: 1
   # nameServers is the [ip:port] list of name service
   nameServers: ""
-  # replicationMode is the broker replica sync mode, can be ASYNC or SYNC
-  replicationMode: ASYNC
   # replicaPerGroup is the number of each broker cluster
   replicaPerGroup: 1
   # brokerImage is the customized docker image repo of the RocketMQ broker
-  brokerImage: apacherocketmq/rocketmq-broker:4.5.0-alpine
+  brokerImage: apacherocketmq/rocketmq-broker:4.5.0-alpine-operator-0.3.0
   # imagePullPolicy is the image pull policy
   imagePullPolicy: Always
   # resources describes the compute resource requirements and limits
@@ -191,8 +205,23 @@ spec:
   storageMode: EmptyDir
   # hostPath is the local path to store data
   hostPath: /data/rocketmq/broker
-  # scalePodName is broker-[broker group number]-master-0
+  # scalePodName is [Broker name]-[broker group number]-master-0
   scalePodName: broker-0-master-0
+  # env defines custom env, e.g. BROKER_MEM
+  env:
+    - name: BROKER_MEM
+      valueFrom:
+        configMapKeyRef:
+          name: broker-config
+          key: BROKER_MEM
+  # volumes defines the broker.conf
+  volumes:
+    - name: broker-config
+      configMap:
+        name: broker-config
+        items:
+          - key: broker-common.conf
+            path: broker-common.conf
   # volumeClaimTemplates defines the storageClass
   volumeClaimTemplates:
     - metadata:
@@ -213,7 +242,7 @@ spec:
   # size is the the name service instance number of the name service cluster
   size: 1
   # nameServiceImage is the customized docker image repo of the RocketMQ name service
-  nameServiceImage: apacherocketmq/rocketmq-nameserver:4.5.0-alpine
+  nameServiceImage: apacherocketmq/rocketmq-nameserver:4.5.0-alpine-operator-0.3.0
   # imagePullPolicy is the image pull policy
   imagePullPolicy: Always
   # hostNetwork can be true or false
diff --git a/create-operator.sh b/create-operator.sh
index b589ad4..02f23b1 100755
--- a/create-operator.sh
+++ b/create-operator.sh
@@ -18,7 +18,7 @@
 set -eux;
 
 # You can change the DOCKERHUB_REPO to your docker repo for development purpose
-DOCKERHUB_REPO="apacherocketmq/rocketmq-operator:0.2.1"
+DOCKERHUB_REPO="apacherocketmq/rocketmq-operator:0.3.0-snapshot"
 # The version of RocketMQ including the Admin Tool
 ROCKETMQ_VERSION="4.5.0"
 
diff --git a/deploy/operator.yaml b/deploy/operator.yaml
index c096ad3..78c4cf9 100644
--- a/deploy/operator.yaml
+++ b/deploy/operator.yaml
@@ -31,7 +31,7 @@ spec:
       containers:
         - name: rocketmq-operator
           # Replace this with the built image name
-          image: apacherocketmq/rocketmq-operator:0.2.1
+          image: apacherocketmq/rocketmq-operator:0.3.0-snapshot
           command:
           - rocketmq-operator
           imagePullPolicy: Always
diff --git a/example/rocketmq_v1alpha1_broker_cr.yaml b/example/rocketmq_v1alpha1_broker_cr.yaml
index f6bea3b..e3d9bd3 100644
--- a/example/rocketmq_v1alpha1_broker_cr.yaml
+++ b/example/rocketmq_v1alpha1_broker_cr.yaml
@@ -18,17 +18,14 @@ kind: ConfigMap
 metadata:
   name: broker-config
 data:
-  BROKER_MEM: " -Xms4g -Xmx4g -Xmn2g "
+  BROKER_MEM: " -Xms2g -Xmx2g -Xmn1g "
   broker-common.conf: |
     # brokerClusterName, brokerName, brokerId are automatically generated by the operator and do not set it manually!!!
     deleteWhen=04
     fileReservedTime=48
     flushDiskType=ASYNC_FLUSH
-    # If it's a slave/replica, the brokerRole will automatically be set to SLAVE
+    # set brokerRole to ASYNC_MASTER or SYNC_MASTER. DO NOT set to SLAVE because the replica instance will automatically be set!!!
     brokerRole=ASYNC_MASTER
-    storePathCommitLog=/home/rocketmq/store/commitlog
-    storePathRootDir=/home/rocketmq/store/
-    storePathScheduledTempData=/home/rocketmq/store/scheduledtempdata
 
 ---
 apiVersion: rocketmq.apache.org/v1alpha1
@@ -44,7 +41,7 @@ spec:
   # replicaPerGroup is the number of each broker cluster
   replicaPerGroup: 1
   # brokerImage is the customized docker image repo of the RocketMQ broker
-  brokerImage: apacherocketmq/rocketmq-broker:4.5.0-alpine
+  brokerImage: apacherocketmq/rocketmq-broker:4.5.0-alpine-operator-0.3.0
   # imagePullPolicy is the image pull policy
   imagePullPolicy: Always
   # resources describes the compute resource requirements and limits
diff --git a/example/rocketmq_v1alpha1_nameservice_cr.yaml b/example/rocketmq_v1alpha1_nameservice_cr.yaml
index a7678aa..291d447 100644
--- a/example/rocketmq_v1alpha1_nameservice_cr.yaml
+++ b/example/rocketmq_v1alpha1_nameservice_cr.yaml
@@ -21,7 +21,7 @@ spec:
   # size is the the name service instance number of the name service cluster
   size: 1
   # nameServiceImage is the customized docker image repo of the RocketMQ name service
-  nameServiceImage: apacherocketmq/rocketmq-nameserver:4.5.0-alpine
+  nameServiceImage: apacherocketmq/rocketmq-nameserver:4.5.0-alpine-operator-0.3.0
   # imagePullPolicy is the image pull policy
   imagePullPolicy: Always
   # hostNetwork can be true or false
diff --git a/example/rocketmq_v1alpha1_rocketmq_cluster.yaml b/example/rocketmq_v1alpha1_rocketmq_cluster.yaml
index f39a2f3..afb01e5 100644
--- a/example/rocketmq_v1alpha1_rocketmq_cluster.yaml
+++ b/example/rocketmq_v1alpha1_rocketmq_cluster.yaml
@@ -13,6 +13,22 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: broker-config
+data:
+  # BROKER_MEM sets the broker JVM, if set to "" then Xms = Xmx = max(min(1/2 ram, 1024MB), min(1/4 ram, 8GB))
+  BROKER_MEM: " -Xms2g -Xmx2g -Xmn1g "
+  broker-common.conf: |
+    # brokerClusterName, brokerName, brokerId are automatically generated by the operator and do not set it manually!!!
+    deleteWhen=04
+    fileReservedTime=48
+    flushDiskType=ASYNC_FLUSH
+    # set brokerRole to ASYNC_MASTER or SYNC_MASTER. DO NOT set to SLAVE because the replica instance will automatically be set!!!
+    brokerRole=ASYNC_MASTER
+
+---
 apiVersion: rocketmq.apache.org/v1alpha1
 kind: Broker
 metadata:
@@ -23,12 +39,10 @@ spec:
   size: 1
   # nameServers is the [ip:port] list of name service
   nameServers: ""
-  # replicationMode is the broker replica sync mode, can be ASYNC or SYNC
-  replicationMode: ASYNC
   # replicaPerGroup is the number of each broker cluster
   replicaPerGroup: 1
   # brokerImage is the customized docker image repo of the RocketMQ broker
-  brokerImage: apacherocketmq/rocketmq-broker:4.5.0-alpine
+  brokerImage: apacherocketmq/rocketmq-broker:4.5.0-alpine-operator-0.3.0
   # imagePullPolicy is the image pull policy
   imagePullPolicy: Always
   # resources describes the compute resource requirements and limits
@@ -45,8 +59,23 @@ spec:
   storageMode: EmptyDir
   # hostPath is the local path to store data
   hostPath: /data/rocketmq/broker
-  # scalePodName is broker-[broker group number]-master-0
+  # scalePodName is [Broker name]-[broker group number]-master-0
   scalePodName: broker-0-master-0
+  # env defines custom env, e.g. BROKER_MEM
+  env:
+    - name: BROKER_MEM
+      valueFrom:
+        configMapKeyRef:
+          name: broker-config
+          key: BROKER_MEM
+  # volumes defines the broker.conf
+  volumes:
+    - name: broker-config
+      configMap:
+        name: broker-config
+        items:
+          - key: broker-common.conf
+            path: broker-common.conf
   # volumeClaimTemplates defines the storageClass
   volumeClaimTemplates:
     - metadata:
@@ -67,7 +96,7 @@ spec:
   # size is the the name service instance number of the name service cluster
   size: 1
   # nameServiceImage is the customized docker image repo of the RocketMQ name service
-  nameServiceImage: apacherocketmq/rocketmq-nameserver:4.5.0-alpine
+  nameServiceImage: apacherocketmq/rocketmq-nameserver:4.5.0-alpine-operator-0.3.0
   # imagePullPolicy is the image pull policy
   imagePullPolicy: Always
   # hostNetwork can be true or false
diff --git a/go.mod b/go.mod
index 637947e..51349d8 100644
--- a/go.mod
+++ b/go.mod
@@ -17,7 +17,7 @@ require (
 	github.com/go-logr/zapr v0.1.1 // indirect
 	github.com/go-openapi/jsonpointer v0.19.0 // indirect
 	github.com/go-openapi/jsonreference v0.19.0 // indirect
-	github.com/go-openapi/spec v0.19.0 // indirect
+	github.com/go-openapi/spec v0.19.0
 	github.com/go-openapi/swag v0.19.0 // indirect
 	github.com/gobuffalo/envy v1.6.15 // indirect
 	github.com/gobwas/glob v0.2.3 // indirect
@@ -69,7 +69,7 @@ require (
 	k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a // indirect
 	k8s.io/helm v2.13.0+incompatible // indirect
 	k8s.io/klog v0.2.0 // indirect
-	k8s.io/kube-openapi v0.0.0-20180711000925-0cf8f7e6ed1d // indirect
+	k8s.io/kube-openapi v0.0.0-20180711000925-0cf8f7e6ed1d
 	sigs.k8s.io/controller-runtime v0.1.10
 	sigs.k8s.io/controller-tools v0.1.8 // indirect
 	sigs.k8s.io/yaml v1.1.0 // indirect
diff --git a/images/broker/alpine/Dockerfile b/images/broker/alpine/Dockerfile
index ef36b44..571451c 100644
--- a/images/broker/alpine/Dockerfile
+++ b/images/broker/alpine/Dockerfile
@@ -25,7 +25,7 @@ ARG version
 ENV ROCKETMQ_VERSION ${version}
 
 # Rocketmq home
-ENV ROCKETMQ_HOME  /home/rocketmq/broker
+ENV ROCKETMQ_HOME  /root/rocketmq/broker
 
 WORKDIR  ${ROCKETMQ_HOME}
 
@@ -34,7 +34,6 @@ RUN set -eux; \
     apk add --virtual .build-deps curl gnupg unzip; \
     curl https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip; \
     curl https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip.asc -o rocketmq.zip.asc; \
-    #https://www.apache.org/dist/rocketmq/KEYS
 	curl https://www.apache.org/dist/rocketmq/KEYS -o KEYS; \
 	\
 	gpg --import KEYS; \
diff --git a/images/broker/alpine/build-broker-image.sh b/images/broker/alpine/build-broker-image.sh
index e02c1ee..7d424cd 100755
--- a/images/broker/alpine/build-broker-image.sh
+++ b/images/broker/alpine/build-broker-image.sh
@@ -34,9 +34,10 @@ fi
 
 ROCKETMQ_VERSION=$1
 DOCKERHUB_REPO=apacherocketmq/rocketmq-broker
+IMAGE_NAME=${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine-operator-0.3.0
 
 checkVersion $ROCKETMQ_VERSION
 
-docker build -t ${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine --build-arg version=${ROCKETMQ_VERSION} .
+docker build -t $IMAGE_NAME --build-arg version=${ROCKETMQ_VERSION} .
 
-docker push ${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine
+docker push $IMAGE_NAME
diff --git a/images/namesrv/alpine/Dockerfile b/images/namesrv/alpine/Dockerfile
index b105d4a..73c1f18 100644
--- a/images/namesrv/alpine/Dockerfile
+++ b/images/namesrv/alpine/Dockerfile
@@ -25,7 +25,7 @@ ARG version
 ENV ROCKETMQ_VERSION ${version}
 
 # Rocketmq home
-ENV ROCKETMQ_HOME  /home/rocketmq/nameserver
+ENV ROCKETMQ_HOME  /root/rocketmq/nameserver
 
 WORKDIR  ${ROCKETMQ_HOME}
 
@@ -34,9 +34,7 @@ RUN set -eux; \
     apk add --virtual .build-deps curl gnupg unzip; \
     curl https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip; \
     curl https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip.asc -o rocketmq.zip.asc; \
-    #https://www.apache.org/dist/rocketmq/KEYS
 	curl https://www.apache.org/dist/rocketmq/KEYS -o KEYS; \
-	\
 	gpg --import KEYS; \
     gpg --batch --verify rocketmq.zip.asc rocketmq.zip; \
     unzip rocketmq.zip; \
diff --git a/images/namesrv/alpine/build-namesrv-image.sh b/images/namesrv/alpine/build-namesrv-image.sh
index d598522..c8dce11 100755
--- a/images/namesrv/alpine/build-namesrv-image.sh
+++ b/images/namesrv/alpine/build-namesrv-image.sh
@@ -34,9 +34,10 @@ fi
 
 ROCKETMQ_VERSION=$1
 DOCKERHUB_REPO=apacherocketmq/rocketmq-nameserver
+IMAGE_NAME=${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine-operator-0.3.0
 
 checkVersion $ROCKETMQ_VERSION
 
-docker build -t ${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine --build-arg version=${ROCKETMQ_VERSION} .
+docker build -t $IMAGE_NAME --build-arg version=${ROCKETMQ_VERSION} .
 
-docker push ${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine
+docker push $IMAGE_NAME
\ No newline at end of file
diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go
index bc35a31..5ebf7da 100644
--- a/pkg/constants/constants.go
+++ b/pkg/constants/constants.go
@@ -19,6 +19,9 @@
 package constants
 
 const (
+	// TODO: get paths by container ENV or actual value instead of fixed constant
+	DataPath = "/root"
+
 	// BrokerContainerName is the name of broker container
 	BrokerContainerName = "broker"
 
@@ -29,16 +32,16 @@ const (
 	AdminToolDir = "/home/rocketmq/operator/bin/mqadmin"
 
 	// StoreConfigDir is the directory of config file
-	StoreConfigDir = "/home/rocketmq/store/config"
+	StoreConfigDir = DataPath + "/store/config"
 
 	// TopicJsonDir is the directory of topics.json
-	TopicJsonDir = "/home/rocketmq/store/config/topics.json"
+	TopicJsonDir = StoreConfigDir + "/topics.json"
 
 	// SubscriptionGroupJsonDir is the directory of subscriptionGroup.json
-	SubscriptionGroupJsonDir = "/home/rocketmq/store/config/subscriptionGroup.json"
+	SubscriptionGroupJsonDir = StoreConfigDir + "/subscriptionGroup.json"
 
 	// BrokerConfigDir is the directory of the mounted config file
-	BrokerConfigPath = "/home/rocketmq/broker/conf"
+	BrokerConfigPath = DataPath + "/rocketmq/broker/conf"
 
 	// BrokerConfigName is the name of mounted configuration file
 	BrokerConfigName = "broker-common.conf"
@@ -62,10 +65,10 @@ const (
 	EnvBrokerName = "BROKER_NAME"
 
 	// LogMountPath is the directory of RocketMQ log files
-	LogMountPath = "/root/logs"
+	LogMountPath = DataPath + "/logs"
 
 	// StoreMountPath is the directory of RocketMQ store files
-	StoreMountPath = "/root/store"
+	StoreMountPath = DataPath + "/store"
 
 	// LogSubPathName is the sub-path name of log dir under mounted host dir
 	LogSubPathName = "logs"
diff --git a/pkg/controller/broker/broker_controller.go b/pkg/controller/broker/broker_controller.go
index 73d34dc..5b2de77 100644
--- a/pkg/controller/broker/broker_controller.go
+++ b/pkg/controller/broker/broker_controller.go
@@ -456,7 +456,7 @@ func (r *ReconcileBroker) getBrokerStatefulSet(broker *rocketmqv1alpha1.Broker,
 func getENV(broker *rocketmqv1alpha1.Broker, replicaIndex int, brokerGroupIndex int)  []corev1.EnvVar {
 	envs := []corev1.EnvVar{{
 		Name:  cons.EnvNameServiceAddress,
-		Value: broker.Spec.NameServers,
+		Value: share.NameServersStr,
 	}, {
 		Name:  cons.EnvBrokerId,
 		Value: strconv.Itoa(replicaIndex),