Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions addons/rocketmq/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions addons/rocketmq/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: rocketmq
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "5.3.2"
119 changes: 119 additions & 0 deletions addons/rocketmq/scripts/rocketmq-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/sh

# shellcheck disable=SC2034

java -version
if [ $? -ne 0 ]; then
echo "[ERROR] Missing java runtime"
exit 50
fi

if [ -z "${ROCKETMQ_HOME}" ]; then
echo "[ERROR] Missing env ROCKETMQ_HOME"
exit 50
fi
if [ -z "${ROCKETMQ_PROCESS_ROLE}" ]; then
echo "[ERROR] Missing env ROCKETMQ_PROCESS_ROLE"
exit 50
fi

export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export CLASSPATH=".:${ROCKETMQ_HOME}/conf:${ROCKETMQ_HOME}/lib/*:${CLASSPATH}"

JAVA_OPT="${JAVA_OPT} -server"
if [ -n "$ROCKETMQ_JAVA_OPTIONS_OVERRIDE" ]; then
JAVA_OPT="${JAVA_OPT} ${ROCKETMQ_JAVA_OPTIONS_OVERRIDE}"
else
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC"
JAVA_OPT="${JAVA_OPT} ${ROCKETMQ_JAVA_OPTIONS_EXT}"
JAVA_OPT="${JAVA_OPT} ${ROCKETMQ_JAVA_OPTIONS_HEAP}"
fi
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"

export BROKER_CONF_FILE="$HOME/broker.conf"
export CONTROLLER_CONF_FILE="$HOME/controller.conf"

update_broker_conf() {
local key=$1
local value=$2
sed -i "/^${key} *=/d" ${BROKER_CONF_FILE}
echo "${key} = ${value}" >> ${BROKER_CONF_FILE}
}

init_broker_role() {
if [ "${ROCKETMQ_CONF_brokerRole}" = "SLAVE" ]; then
update_broker_conf "brokerRole" "SLAVE"
elif [ "${ROCKETMQ_CONF_brokerRole}" = "SYNC_MASTER" ]; then
update_broker_conf "brokerRole" "SYNC_MASTER"
else
update_broker_conf "brokerRole" "ASYNC_MASTER"
fi
if echo "${ROCKETMQ_CONF_brokerId}" | grep -E '^[0-9]+$'; then
update_broker_conf "brokerId" "${ROCKETMQ_CONF_brokerId}"
fi
}

init_broker_conf() {
rm -f ${BROKER_CONF_FILE}
cp /etc/rocketmq/broker-base.conf ${BROKER_CONF_FILE}
echo "" >> ${BROKER_CONF_FILE}
echo "# generated config" >> ${BROKER_CONF_FILE}
broker_name_seq=${HOSTNAME##*-}
if [ -n "$POD_NAME" ]; then
broker_name_seq=${POD_NAME##*-}
fi
update_broker_conf "brokerName" "broker-g${broker_name_seq}"
if [ "$enableControllerMode" != "true" ]; then
init_broker_role
fi
echo "[exec] cat ${BROKER_CONF_FILE}"
cat ${BROKER_CONF_FILE}
}

init_acl_conf() {
if [ -f /etc/rocketmq/acl/plain_acl.yml ]; then
rm -f "${ROCKETMQ_HOME}/conf/plain_acl.yml"
ln -sf "/etc/rocketmq/acl" "${ROCKETMQ_HOME}/conf/acl"
fi
}

init_controller_conf() {
rm -f ${CONTROLLER_CONF_FILE}
cp /etc/rocketmq/base-cm/controller-base.conf ${CONTROLLER_CONF_FILE}
controllerDLegerSelfId="n${HOSTNAME##*-}"
if [ -n "$MY_POD_NAME" ]; then
controllerDLegerSelfId="n${MY_POD_NAME##*-}"
fi
sed -i "/^controllerDLegerSelfId *=/d" ${CONTROLLER_CONF_FILE}
echo "controllerDLegerSelfId = ${controllerDLegerSelfId}" >> ${CONTROLLER_CONF_FILE}
cat ${CONTROLLER_CONF_FILE}
}

if [ "$ROCKETMQ_PROCESS_ROLE" = "broker" ]; then
init_broker_conf
init_acl_conf
set -x
java ${JAVA_OPT} org.apache.rocketmq.broker.BrokerStartup -c ${BROKER_CONF_FILE}
elif [ "$ROCKETMQ_PROCESS_ROLE" = "controller" ]; then
init_controller_conf
set -x
java ${JAVA_OPT} org.apache.rocketmq.controller.ControllerStartup -c ${CONTROLLER_CONF_FILE}
elif [ "$ROCKETMQ_PROCESS_ROLE" = "nameserver" ] || [ "$ROCKETMQ_PROCESS_ROLE" = "mqnamesrv" ]; then
set -x
if [ "$enableControllerInNamesrv" = "true" ]; then
init_controller_conf
java ${JAVA_OPT} org.apache.rocketmq.namesrv.NamesrvStartup -c ${CONTROLLER_CONF_FILE}
else
java ${JAVA_OPT} org.apache.rocketmq.namesrv.NamesrvStartup
fi
elif [ "$ROCKETMQ_PROCESS_ROLE" = "proxy" ]; then
set -x
if [ -f $RMQ_PROXY_CONFIG_PATH ]; then
java ${JAVA_OPT} org.apache.rocketmq.proxy.ProxyStartup -pc $RMQ_PROXY_CONFIG_PATH
else
java ${JAVA_OPT} org.apache.rocketmq.proxy.ProxyStartup
fi
else
echo "[ERROR] Missing env ROCKETMQ_PROCESS_ROLE"
exit 50
fi
Empty file.
127 changes: 127 additions & 0 deletions addons/rocketmq/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "rocketmq.name" -}}
{{- default .Chart.Name .Values.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 "rocketmq.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.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 "rocketmq.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "rocketmq.labels" -}}
helm.sh/chart: {{ include "rocketmq.chart" . }}
{{ include "rocketmq.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "rocketmq.selectorLabels" -}}
app.kubernetes.io/name: {{ include "rocketmq.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "rocketmq.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "rocketmq.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Common annotations
*/}}
{{- define "rocketmq.annotations" -}}
{{ include "rocketmq.apiVersion" . }}
{{- end }}

{{/*
API version annotation
*/}}
{{- define "rocketmq.apiVersion" -}}
kubeblocks.io/crd-api-version: apps.kubeblocks.io/v1
{{- end }}


{{/*
controller
*/}}
{{- define "rocketmq.controller.fullname" -}}
{{ include "rocketmq.fullname" . }}-controller
{{- end -}}

{{/*
controller
*/}}
{{- define "rocketmq.enableControllerInNamesrv" -}}
{{- if and .Values.controllerModeEnabled (not .Values.controller.enabled) -}}
{{- print "true" -}}
{{- else -}}
{{- print "false" -}}
{{- end -}}
{{- end -}}

{{/*
rocketmq.controller.dlegerPeers
*/}}
{{- define "rocketmq.controller.dlegerPeers" -}}
{{- $address := list -}}
{{- $fullName := include "rocketmq.controller.fullname" . -}}
{{- $headlessDomain := printf "%s.%s.svc" $fullName .Release.Namespace -}}
{{- $replicaCount := int .Values.controller.replicaCount -}}
{{- if eq (include "rocketmq.enableControllerInNamesrv" .) "true" -}}
{{- $fullName = include "rocketmq.nameserver.fullname" . -}}
{{- $headlessDomain = printf "%s-headless.%s.svc" $fullName .Release.Namespace -}}
{{- $replicaCount = int .Values.nameserver.replicaCount -}}
{{- end -}}
{{- range $i := until $replicaCount -}}
{{- $address = printf "n%d-%s-%d.%s:9878" $i $fullName $i $headlessDomain | append $address -}}
{{- end -}}
{{- join ";" $address -}}
{{- end -}}

{{/*
env NAMESRV_ADDR
*/}}
{{- define "rocketmq.nameserver.addr" -}}
{{- $headlessDomain := printf "svc-headless.%s.svc" .Release.Namespace -}}
{{- $address := list -}}
{{- $replicaCount := int .Values.nameserver.replicaCount -}}
{{- range $i := until $replicaCount -}}
{{- $address = printf "svc-%d.%s:9876" $i $headlessDomain | append $address -}}
{{- end -}}
{{- join ";" $address -}}
{{- end -}}
65 changes: 65 additions & 0 deletions addons/rocketmq/templates/_names.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{/*
Define cluster definition name, if resourceNamePrefix is specified, use it as clusterDefName
*/}}
{{- define "rocketmq.clusterDefName" -}}
{{- if eq (len .Values.resourceNamePrefix) 0 -}}
rocketmq
{{- else -}}
{{- .Values.resourceNamePrefix -}}
{{- end -}}
{{- end -}}

{{/*
Define rocketmq component definition name prefix
*/}}
{{- define "rocketmq.cmpdNamePrefix" -}}
{{- default "rocketmq" .Values.resourceNamePrefix -}}-
{{- end -}}

{{/*
Define rocketmq component definition name
*/}}
{{- define "rocketmq.cmpdName" -}}
{{ include "rocketmq.cmpdNamePrefix" . }}{{ .Chart.Version }}
{{- end -}}

{{/*
Define rocketmq pcr definition name
*/}}
{{- define "rocketmq.pcrName" -}}
{{ include "rocketmq.cmpdNamePrefix" . }}pcr
{{- end -}}

{{/*
Define rocketmq pcr definition name
*/}}
{{- define "rocketmq.paramsDefName" -}}
{{ include "rocketmq.cmpdNamePrefix" . }}pd
{{- end -}}

{{/*
Define config constriant name
*/}}
{{- define "rocketmq.configConstraintName" -}}
{{- if eq (len .Values.resourceNamePrefix) 0 -}}
rocketmq-config-constraints
{{- else -}}
{{- .Values.resourceNamePrefix -}}-config-constraints
{{- end -}}
{{- end -}}

{{- define "rocketmq.configTplName" -}}
{{- if eq (len .Values.resourceNamePrefix) 0 -}}
rocketmq-config-template
{{- else -}}
{{- .Values.resourceNamePrefix -}}-config-template
{{- end -}}
{{- end -}}

{{- define "rocketmq.cmScriptsName" }}
{{- if eq (len .Values.resourceNamePrefix) 0 -}}
rocketmq-scripts
{{- else -}}
{{- .Values.resourceNamePrefix -}}-scripts
{{- end -}}
{{- end -}}
15 changes: 15 additions & 0 deletions addons/rocketmq/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apps.kubeblocks.io/v1
kind: ClusterDefinition
metadata:
name: rocketmq
labels:
{{- include "rocketmq.labels" . | nindent 4 }}
annotations:
{{- include "rocketmq.apiVersion" . | nindent 4 }}
spec:
topologies:
- name: clustermode
components:
- name: rocketmq
compDef: {{ include "rocketmq.cmpdNamePrefix" . }}
default: true
Loading
Loading