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

jinrongtong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-docker.git


The following commit(s) were added to refs/heads/master by this push:
     new e115424  [ISSUE #104] Add helm templates for rocketmq-controller
e115424 is described below

commit e115424899316b0302588615c3f4815be8cfda3e
Author: caigy <csgyt...@163.com>
AuthorDate: Tue Apr 9 11:36:07 2024 +0800

    [ISSUE #104] Add helm templates for rocketmq-controller
---
 .../templates/controller/_controllerconfig.tpl     |  50 ++++++++++
 .../templates/controller/_helpers.tpl              |  55 +++++++++++
 .../templates/controller/configmap.yaml            |  12 +++
 .../templates/controller/service.yaml              |  25 +++++
 .../templates/controller/statefulset.yaml          | 109 +++++++++++++++++++++
 rocketmq-k8s-helm/values.yaml                      |  42 +++++++-
 6 files changed, 292 insertions(+), 1 deletion(-)

diff --git a/rocketmq-k8s-helm/templates/controller/_controllerconfig.tpl 
b/rocketmq-k8s-helm/templates/controller/_controllerconfig.tpl
new file mode 100644
index 0000000..76ba63e
--- /dev/null
+++ b/rocketmq-k8s-helm/templates/controller/_controllerconfig.tpl
@@ -0,0 +1,50 @@
+{{- /*
+SPDX-License-Identifier: APACHE-2.0
+*/}}
+
+{{- define "controller.jRaftInitConf" -}}
+{{- $replicaCount := .Values.controller.replicas | int }}
+{{- $args := list -}}
+{{- $name := include "controller.fullname" . }}
+{{- $namespace := .Release.Namespace -}}
+{{- $result := "" -}}
+{{- $port := .Values.controller.service.internalport | int -}}
+{{- range untilStep 0 $replicaCount 1 -}}
+{{-   $args = printf "%s-%d.%s.%s:%d" $name . $name $namespace $port | append 
$args -}}
+{{- end }}
+   {{- $result = printf "%s=%s" "jRaftInitConf" (join "," $args) -}}
+   {{- $result -}}
+{{- end -}}
+
+{{- define "controller.jRaftControllerRPCAddr" -}}
+{{- $replicaCount := .Values.controller.replicas | int }}
+{{- $args := list -}}
+{{- $name := include "controller.fullname" . }}
+{{- $namespace := .Release.Namespace -}}
+{{- $result := "" -}}
+{{- $port := .Values.controller.service.port | int -}}
+{{- range untilStep 0 $replicaCount 1 -}}
+{{-   $args = printf "%s-%d.%s.%s:%d" $name . $name $namespace $port | append 
$args -}}
+{{- end }}
+   {{- $result = printf "%s=%s" "jRaftControllerRPCAddr" (join "," $args) -}}
+   {{- $result -}}
+{{- end -}}
+
+{{- define "controller.config" -}}
+{{- $name := include "controller.fullname" . }}
+{{- $config := .Values.controller.config }}
+{{- $replicaCount := .Values.controller.replicas | int }}
+{{- $jRaftInitConf := include "controller.jRaftInitConf" . -}}
+{{- $jRaftControllerRPCAddr := include "controller.jRaftControllerRPCAddr" . 
-}}
+{{- range $index := until $replicaCount }}
+  {{ $name }}-{{ $index }}: |
+    controllerType=jRaft
+    jRaftGroupId=jRaft-controller-group
+    jRaftServerId = {{ $name }}-{{ $index }}.{{ $name }}.{{ 
$.Release.Namespace }}:{{ $.Values.controller.service.internalport }}  
+    {{ $jRaftInitConf }}
+    {{ $jRaftControllerRPCAddr }}
+    jRaftSnapshotIntervalSecs = 3600
+    controllerStorePath=/home/rocketmq/store
+{{ $config | indent 4 }}
+{{- end }}
+{{- end }}
diff --git a/rocketmq-k8s-helm/templates/controller/_helpers.tpl 
b/rocketmq-k8s-helm/templates/controller/_helpers.tpl
new file mode 100644
index 0000000..f1628fb
--- /dev/null
+++ b/rocketmq-k8s-helm/templates/controller/_helpers.tpl
@@ -0,0 +1,55 @@
+{{- /*
+SPDX-License-Identifier: APACHE-2.0
+*/}}
+
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "controller.name" -}}
+{{- default .Chart.Name .Values.controller.nameOverride | trunc 63 | 
trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to 
this (by the DNS naming spec).
+If release name contains chart name it will be used as a full name.
+*/}}
+{{- define "controller.fullname" -}}
+{{- if .Values.fullnameOverride }}
+{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- $name := default .Chart.Name .Values.controller.nameOverride }}
+{{- if contains $name .Release.Name }}
+{{- .Release.Name | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+{{- end }}
+{{- end }}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "controller.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | 
trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "controller.labels" -}}
+helm.sh/chart: {{ include "controller.chart" . }}
+{{ include "controller.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "controller.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "controller.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end }}
diff --git a/rocketmq-k8s-helm/templates/controller/configmap.yaml 
b/rocketmq-k8s-helm/templates/controller/configmap.yaml
new file mode 100644
index 0000000..59d07e6
--- /dev/null
+++ b/rocketmq-k8s-helm/templates/controller/configmap.yaml
@@ -0,0 +1,12 @@
+{{- /*
+SPDX-License-Identifier: APACHE-2.0
+*/}}
+
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "controller.fullname" . }}-conf
+  labels:
+    {{- include "controller.labels" . | nindent 4 }}
+data:
+{{- include "controller.config" . }}
\ No newline at end of file
diff --git a/rocketmq-k8s-helm/templates/controller/service.yaml 
b/rocketmq-k8s-helm/templates/controller/service.yaml
new file mode 100644
index 0000000..b458836
--- /dev/null
+++ b/rocketmq-k8s-helm/templates/controller/service.yaml
@@ -0,0 +1,25 @@
+{{- /*
+SPDX-License-Identifier: APACHE-2.0
+*/}}
+
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "controller.fullname" . }}
+  labels:
+    {{- include "controller.labels" . | nindent 4 }}
+spec:
+  type: ClusterIP
+  clusterIP: None
+  ports:
+  - name: main
+    port: {{ .Values.controller.service.port }}
+    protocol: TCP
+    targetPort: main
+  - name: internal
+    port: {{ .Values.controller.service.internalport }}
+    protocol: TCP
+    targetPort: internal
+  publishNotReadyAddresses: true
+  selector:
+    {{- include "controller.selectorLabels" . | nindent 4 }}
diff --git a/rocketmq-k8s-helm/templates/controller/statefulset.yaml 
b/rocketmq-k8s-helm/templates/controller/statefulset.yaml
new file mode 100644
index 0000000..c6c2271
--- /dev/null
+++ b/rocketmq-k8s-helm/templates/controller/statefulset.yaml
@@ -0,0 +1,109 @@
+{{- /*
+SPDX-License-Identifier: APACHE-2.0
+*/}}
+
+apiVersion: apps/v1
+kind: StatefulSet
+metadata: 
+  name: {{ include "controller.fullname" . }}
+  labels:
+    {{- include "controller.labels" . | nindent 4 }}
+spec:
+  replicas: {{ .Values.controller.replicas }}
+  selector:
+    matchLabels:
+      {{- include "controller.selectorLabels" . | nindent 6 }}
+  serviceName: {{ include "controller.fullname" . }}
+  template: 
+    metadata: 
+      annotations: 
+        checksum/config: {{ include (print $.Template.BasePath 
"/controller/configmap.yaml") . | sha256sum }}
+      labels:
+        {{- include "controller.labels" . | nindent 8 }}
+    spec: 
+      {{- with .Values.controller.image.pullSecrets }}
+      imagePullSecrets:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.controller.affinity }}
+      affinity:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.controller.nodeSelector }}
+      nodeSelector:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.controller.tolerations }}
+      tolerations:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      containers: 
+      - name: controller
+        image: "{{ .Values.controller.image.registry }}/{{ 
.Values.controller.image.repository }}:{{ .Values.controller.image.tag }}"
+        imagePullPolicy: {{ .Values.controller.image.pullPolicy }}
+        env: 
+        - name: NODE_ROLE
+          value: controller
+        - name: POD_NAME
+          valueFrom:
+            fieldRef:
+              apiVersion: v1
+              fieldPath: metadata.name
+        command: [ "/bin/sh" ]
+        args: [ "-c", "./mqcontroller -c /home/rocketmq/conf/$(POD_NAME)" ]
+        ports:
+        - name: main
+          containerPort: {{ .Values.controller.service.port }}
+          protocol: TCP
+        - name: internal
+          containerPort: {{  .Values.controller.service.internalport }}
+          protocol: TCP
+        livenessProbe:
+        {{- toYaml .Values.controller.livenessProbe | nindent 10 }}
+        readinessProbe:
+        {{- toYaml .Values.controller.readinessProbe | nindent 10 }}
+        startupProbe:
+        {{- toYaml .Values.controller.startupProbe | nindent 10 }}
+        resources: 
+        {{- toYaml .Values.controller.resources  | nindent 10 }}
+        volumeMounts:
+        - mountPath: /home/rocketmq/conf
+          name: controller-config
+        - mountPath: /home/rocketmq/logs
+          name: controller-storage
+          subPath: logs
+        - mountPath: /home/rocketmq/store
+          name: controller-storage
+          subPath: store
+      securityContext:
+        fsGroup: 3000
+      volumes:
+      - name: controller-config
+        configMap:
+          name: {{ include "controller.fullname" . }}-conf
+      {{- if not $.Values.controller.persistence.enabled }}
+      - name: controller-storage
+        emptyDir: { }
+      {{- else if .Values.controller.persistence.existingClaim }}
+      - name: controller-storage
+        persistentVolumeClaim:
+          claimName: {{ printf "%s" (tpl 
.Values.controller.persistence.existingClaim .) }}
+      {{- end }}
+  {{- if and .Values.controller.persistence.enabled (not 
.Values.controller.persistence.existingClaim) }}
+  volumeClaimTemplates:
+    - metadata:
+        name: controller-storage
+      spec:
+        accessModes: [ "ReadWriteOnce" ]
+        resources:
+          requests:
+            storage:  {{ .Values.controller.persistence.size | quote }}
+        {{- if (eq "-" .Values.controller.persistence.storageClass) -}}
+        storageClassName: ""
+        {{- else }}
+        storageClassName: {{ .Values.controller.persistence.storageClass }}
+        {{- end -}}        
+  {{- end }}
+
+
+
diff --git a/rocketmq-k8s-helm/values.yaml b/rocketmq-k8s-helm/values.yaml
index 87b8887..bf27e04 100644
--- a/rocketmq-k8s-helm/values.yaml
+++ b/rocketmq-k8s-helm/values.yaml
@@ -199,4 +199,44 @@ broker:
 
   nodeSelector: { }
 
-  tolerations: [ ]
\ No newline at end of file
+  tolerations: [ ]
+
+controller:
+  nameOverride: "controller"
+  fullnameOverride: ""
+  replicas: 3
+  image:
+    registry: docker.io
+    repository: "apache/rocketmq"
+    tag: "latest"
+    pullPolicy: IfNotPresent
+  service:
+    port: 9878
+    internalport: 9888
+  resources:
+    limits: 
+      cpu: 2
+      memory: 4Gi
+    requests:
+      cpu: 1
+      memory: 4Gi
+  readinessProbe:
+    tcpSocket:
+      port: 9878
+    initialDelaySeconds: 5
+    periodSeconds: 10
+  livenessProbe:
+    tcpSocket:
+      port: 9878
+    periodSeconds: 10
+  startupProbe:
+    tcpSocket:
+      port: 9878
+    failureThreshold: 30
+    periodSeconds: 10
+    successThreshold: 1
+    timeoutSeconds: 10
+  config: ""
+  persistence:
+    enabled: false
+    size: 20Gi

Reply via email to