Skip to content

Commit 2d0ca25

Browse files
committed
add rocketmq addon
Signed-off-by: dongjiang <dongjiang1989@126.com>
1 parent 7ce33f9 commit 2d0ca25

File tree

8 files changed

+467
-11
lines changed

8 files changed

+467
-11
lines changed

addons/rocketmq/scripts/rocketmq-start.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
# shellcheck disable=SC2034
44

@@ -59,8 +59,8 @@ init_broker_conf() {
5959
echo "" >> ${BROKER_CONF_FILE}
6060
echo "# generated config" >> ${BROKER_CONF_FILE}
6161
broker_name_seq=${HOSTNAME##*-}
62-
if [ -n "$MY_POD_NAME" ]; then
63-
broker_name_seq=${MY_POD_NAME##*-}
62+
if [ -n "$POD_NAME" ]; then
63+
broker_name_seq=${POD_NAME##*-}
6464
fi
6565
update_broker_conf "brokerName" "broker-g${broker_name_seq}"
6666
if [ "$enableControllerMode" != "true" ]; then

addons/rocketmq/templates/_helpers.tpl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,17 @@ rocketmq.controller.dlegerPeers
111111
{{- $address = printf "n%d-%s-%d.%s:9878" $i $fullName $i $headlessDomain | append $address -}}
112112
{{- end -}}
113113
{{- join ";" $address -}}
114-
{{- end -}}
114+
{{- end -}}
115+
116+
{{/*
117+
env NAMESRV_ADDR
118+
*/}}
119+
{{- define "rocketmq.nameserver.addr" -}}
120+
{{- $headlessDomain := printf "svc-headless.%s.svc" .Release.Namespace -}}
121+
{{- $address := list -}}
122+
{{- $replicaCount := int .Values.nameserver.replicaCount -}}
123+
{{- range $i := until $replicaCount -}}
124+
{{- $address = printf "svc-%d.%s:9876" $i $headlessDomain | append $address -}}
125+
{{- end -}}
126+
{{- join ";" $address -}}
127+
{{- end -}}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{{- $cmpdName := include "rocketmq.cmpdName" . -}}
2+
{{- $labels := include "rocketmq.labels" . -}}
3+
{{- $annotations := include "rocketmq.annotations" . -}}
4+
{{- $configTplName := include "rocketmq.configTplName" . -}}
5+
{{- $fullName := include "rocketmq.fullname" . -}}
6+
{{- $masterSize := int .Values.broker.size.master -}}
7+
{{- $replicaCount := int (add1 .Values.broker.size.replica) -}}
8+
{{- $image := printf "%s:%s" .Values.rocketmq.repository .Values.rocketmq.tag -}}
9+
{{- range $brokerId := until $replicaCount -}}
10+
{{- $brokerFullName := printf "%s-broker-master" $fullName -}}
11+
{{- $brokerRole := $.Values.broker.master.brokerRole -}}
12+
{{- $brokerConfigKey := "broker-master.conf" -}}
13+
{{- if gt $brokerId 0 }}
14+
{{- $brokerFullName = printf "%s-broker-replica-id%d" $fullName $brokerId -}}
15+
{{- $brokerRole = "SLAVE" -}}
16+
{{- $brokerConfigKey = "broker-slave.conf" -}}
17+
{{- end }}
18+
---
19+
apiVersion: apps.kubeblocks.io/v1
20+
kind: ComponentDefinition
21+
metadata:
22+
name: {{ $cmpdName | quote }}
23+
labels:
24+
{{ $labels | nindent 4 }}
25+
annotations:
26+
{{ $annotations | nindent 4 }}
27+
spec:
28+
provider: kubeblocks.io
29+
description: RocketMQ Broker is a reliable and mature messaging and streaming broker.
30+
serviceKind: broker
31+
serviceVersion: {{ $.Values.componentServiceVersion.controller }}
32+
services:
33+
- name: vip
34+
spec:
35+
ports:
36+
- name: vip
37+
port: 10909
38+
targetPort: vip
39+
- name: main
40+
spec:
41+
ports:
42+
- name: main
43+
port: 10911
44+
targetPort: main
45+
- name: ha
46+
spec:
47+
ports:
48+
- name: ha
49+
port: 10912
50+
targetPort: ha
51+
configs:
52+
- name: config
53+
template: {{ $configTplName | quote }}
54+
volumeName: rocketmq-config
55+
namespace: {{ $.Release.Namespace }}
56+
defaultMode: 0644
57+
restartOnFileChange: false
58+
systemAccounts:
59+
- name: root
60+
initAccount: true
61+
passwordGenerationPolicy:
62+
length: 16
63+
numDigits: 8
64+
numSymbols: 0
65+
letterCase: MixedCases
66+
policyRules:
67+
- apiGroups:
68+
- ""
69+
resources:
70+
- endpoints
71+
verbs:
72+
- get
73+
- apiGroups:
74+
- ""
75+
resources:
76+
- events
77+
verbs:
78+
- create
79+
runtime:
80+
automountServiceAccountToken: true
81+
affinity:
82+
podAntiAffinity:
83+
requiredDuringSchedulingIgnoredDuringExecution:
84+
- labelSelector:
85+
matchLabels:
86+
app.kubernetes.io/component: broker
87+
topologyKey: kubernetes.io/hostname
88+
{{- if $.Values.broker.hostNetwork }}
89+
hostNetwork: true
90+
dnsPolicy: ClusterFirstWithHostNet
91+
{{- else }}
92+
dnsPolicy: {{ $.Values.broker.dnsPolicy | default "ClusterFirst" }}
93+
{{- end }}
94+
terminationGracePeriodSeconds: {{ $.Values.broker.terminationGracePeriodSeconds | default 30 }}
95+
containers:
96+
- name: broker
97+
command:
98+
- sh
99+
- -c
100+
- /rocketmq-start.sh
101+
env:
102+
- name: POD_NAME
103+
valueFrom:
104+
fieldRef:
105+
apiVersion: v1
106+
fieldPath: metadata.name
107+
- name: POD_NAMESPACE
108+
valueFrom:
109+
fieldRef:
110+
apiVersion: v1
111+
fieldPath: metadata.namespace
112+
- name: ROCKETMQ_PROCESS_ROLE
113+
value: broker
114+
- name: NAMESRV_ADDR
115+
value: {{ include "rocketmq.nameserver.addr" $ }}
116+
- name: ROCKETMQ_CONF_brokerId
117+
value: {{ $brokerId | quote }}
118+
- name: ROCKETMQ_CONF_brokerRole
119+
value: {{ $brokerRole | quote }}
120+
{{- if and $.Values.controllerModeEnabled }}
121+
- name: enableControllerMode
122+
value: "true"
123+
{{- end }}
124+
{{- with $.Values.broker.commonEnvs }}
125+
{{- toYaml . | nindent 10 }}
126+
{{- end }}
127+
{{- with $.Values.broker.extraEnvs }}
128+
{{- toYaml . | nindent 10 }}
129+
{{- end }}
130+
image: {{ $.Values.rocketmq.registry | default "docker.io" }}/{{ $.Values.rocketmq.repository }}:{{ $.Values.rocketmq.tag }}
131+
imagePullPolicy: {{ default "IfNotPresent" $.Values.rocketmq.pullPolicy }}
132+
lifecycle:
133+
preStop:
134+
exec:
135+
command:
136+
- sh
137+
- -c
138+
- sleep 5; ./mqshutdown broker
139+
ports:
140+
- containerPort: 10911
141+
name: main
142+
protocol: TCP
143+
- containerPort: 10912
144+
name: ha
145+
protocol: TCP
146+
- containerPort: 10909
147+
name: vip
148+
protocol: TCP
149+
volumeMounts:
150+
- mountPath: {{ $.Values.dataMountPath }}
151+
name: data
152+
- mountPath: /etc/rocketmq/acl
153+
name: rocketmq-config
154+
- mountPath: /rocketmq-start.sh
155+
name: rocketmq-config
156+
subPath: rocketmq-start.sh
157+
- mountPath: /etc/rocketmq/{{ $brokerConfigKey | quote }}
158+
name: rocketmq-config
159+
subPath: broker-base.conf
160+
- mountPath: {{ $.Values.dataMountPath }}/store
161+
name: data
162+
subPath: store
163+
- mountPath: {{ $.Values.dataMountPath }}/logs
164+
name: data
165+
subPath: logs
166+
vars:
167+
- name: CLUSTER_NAME
168+
valueFrom:
169+
clusterVarRef:
170+
clusterName: Required
171+
- name: CLUSTER_NAMESPACE
172+
valueFrom:
173+
clusterVarRef:
174+
namespace: Required
175+
- name: CLUSTER_COMPONENT_NAME
176+
valueFrom:
177+
componentVarRef:
178+
optional: false
179+
componentName: Required
180+
{{- end }}

addons/rocketmq/templates/cmpd-controller.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ spec:
6161
containers:
6262
- name: controller
6363
command:
64-
- /bin/sh
64+
- sh
6565
- -c
66-
- |
67-
cp /root/erlang.cookie /var/lib/rabbitmq/.erlang.cookie
68-
chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
69-
chmod 400 /var/lib/rabbitmq/.erlang.cookie
70-
exec /opt/rabbitmq/sbin/rabbitmq-server
66+
- /rocketmq-start.sh
7167
env:
7268
- name: POD_NAME
7369
valueFrom:
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
apiVersion: apps.kubeblocks.io/v1
2+
kind: ComponentDefinition
3+
metadata:
4+
name: {{ include "rocketmq.cmpdName" . }}
5+
labels:
6+
{{- include "rocketmq.labels" . | nindent 4 }}
7+
annotations:
8+
{{- include "rocketmq.annotations" . | nindent 4 }}
9+
spec:
10+
provider: kubeblocks.io
11+
description: RocketMQ Nameserver is a reliable and mature messaging and streaming broker.
12+
serviceKind: nameserver
13+
serviceVersion: {{ .Values.componentServiceVersion.nameserver }}
14+
services:
15+
- name: svc-headless
16+
spec:
17+
## headless service
18+
clusterIP: None
19+
publishNotReadyAddresses: true
20+
ports:
21+
- name: main
22+
port: 9876
23+
targetPort: main
24+
- name: svr
25+
spec:
26+
ports:
27+
- name: main
28+
port: 9876
29+
targetPort: main
30+
configs:
31+
- name: config
32+
template: {{ include "rocketmq.configTplName" . }}
33+
volumeName: rocketmq-config
34+
namespace: {{ .Release.Namespace }}
35+
defaultMode: 0644
36+
restartOnFileChange: true
37+
systemAccounts:
38+
- name: root
39+
initAccount: true
40+
passwordGenerationPolicy:
41+
length: 16
42+
numDigits: 8
43+
numSymbols: 0
44+
letterCase: MixedCases
45+
policyRules:
46+
- apiGroups:
47+
- ""
48+
resources:
49+
- endpoints
50+
verbs:
51+
- get
52+
- apiGroups:
53+
- ""
54+
resources:
55+
- events
56+
verbs:
57+
- create
58+
runtime:
59+
automountServiceAccountToken: true
60+
affinity:
61+
podAntiAffinity:
62+
requiredDuringSchedulingIgnoredDuringExecution:
63+
- labelSelector:
64+
matchLabels:
65+
app.kubernetes.io/component: nameserver
66+
topologyKey: kubernetes.io/hostname
67+
containers:
68+
- name: nameserver
69+
command:
70+
- /bin/sh
71+
- -c
72+
- /rocketmq-start.sh
73+
env:
74+
- name: POD_NAME
75+
valueFrom:
76+
fieldRef:
77+
apiVersion: v1
78+
fieldPath: metadata.name
79+
- name: POD_NAMESPACE
80+
valueFrom:
81+
fieldRef:
82+
apiVersion: v1
83+
fieldPath: metadata.namespace
84+
- name: ROCKETMQ_PROCESS_ROLE
85+
value: nameserver
86+
{{- if eq (include "rocketmq.enableControllerInNamesrv" $) "true" }}
87+
- name: enableControllerInNamesrv
88+
value: "true"
89+
{{- end }}
90+
image: {{ .Values.rocketmq.registry | default "docker.io" }}/{{ .Values.rocketmq.repository }}:{{ .Values.rocketmq.tag }}
91+
imagePullPolicy: {{ default "IfNotPresent" .Values.rocketmq.pullPolicy }}
92+
lifecycle:
93+
preStop:
94+
exec:
95+
command:
96+
- sh
97+
- -c
98+
- sleep 5; ./mqshutdown namesrv
99+
ports:
100+
- containerPort: 9876
101+
name: main
102+
protocol: TCP
103+
volumeMounts:
104+
- mountPath: {{ .Values.dataMountPath }}
105+
name: data
106+
- mountPath: /etc/rocketmq/base-cm
107+
name: rocketmq-config
108+
- mountPath: /rocketmq-start.sh
109+
name: rocketmq-config
110+
subPath: rocketmq-start.sh
111+
- mountPath: {{ .Values.dataMountPath }}/controller-data
112+
name: data
113+
subPath: controller-data
114+
- mountPath: {{ .Values.dataMountPath }}/logs
115+
name: data
116+
subPath: logs
117+
vars:
118+
- name: CLUSTER_NAME
119+
valueFrom:
120+
clusterVarRef:
121+
clusterName: Required
122+
- name: CLUSTER_NAMESPACE
123+
valueFrom:
124+
clusterVarRef:
125+
namespace: Required
126+
- name: CLUSTER_COMPONENT_NAME
127+
valueFrom:
128+
componentVarRef:
129+
optional: false
130+
componentName: Required

0 commit comments

Comments
 (0)