diff --git a/rocketmq-k8s-helm/clean-ci.sh b/rocketmq-k8s-helm/clean-ci.sh new file mode 100644 index 0000000..fcd50c9 --- /dev/null +++ b/rocketmq-k8s-helm/clean-ci.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +NAMESPACE=$1 + +if [[ -z $NAMESPACE ]]; then + NAMESPACE="default" + echo "info: NAMESPACE is empty, use default namespace: $NAMESPACE" +fi + +helm uninstall s3-localstack --namespace $NAMESPACE +helm uninstall mysql --namespace $NAMESPACE +helm uninstall rocketmq-on-s3 --namespace $NAMESPACE + +kubectl delete -f deploy/init-db-configmap.yaml --namespace $NAMESPACE \ No newline at end of file diff --git a/rocketmq-k8s-helm/deploy-ci.sh b/rocketmq-k8s-helm/deploy-ci.sh index ec23727..29f3d7e 100644 --- a/rocketmq-k8s-helm/deploy-ci.sh +++ b/rocketmq-k8s-helm/deploy-ci.sh @@ -1,18 +1,84 @@ #!/bin/bash -# echo $KUBE_CONFIG_DATA | base64 -d > ./config -# DB_SCRIPTS=$1 +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +ROCKETMQ_REPO=$1 +ROCKETMQ_VERSION=$2 +NAMESPACE=$3 + +if [ $# -lt 2 ]; then + echo -e "Usage: sh $0 ROCKETMQ_REPO ROCKETMQ_VERSION\nExample: sh $0 rocketmq-on-s3 latest" + exit 1 +fi + +if [[ -z $NAMESPACE ]]; then + NAMESPACE="default" + echo "info: NAMESPACE is empty, use default namespace: $NAMESPACE" +fi + +echo "************************************" +echo "* init config... *" +echo "************************************" + + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +REPO_DIR=$(dirname "$(dirname "$SCRIPT_DIR")") +echo "SCRIPT_DIR: $SCRIPT_DIR" +echo "REPO_DIR: $REPO_DIR" +cd "$SCRIPT_DIR" || exit 1 +if [ ! -f "deploy/ddl.sql" ] +then + cp "$REPO_DIR/controller/src/main/resources/ddl.sql" deploy/ +fi + +# make ddl to configmap +if [ ! -f "deploy/init-db-configmap.yaml" ] +then + cp deploy/configmap-template.yaml deploy/init-db-configmap.yaml + sed 's/^/ /' deploy/ddl.sql >> deploy/init-db-configmap.yaml +fi + +kubectl apply -f deploy/init-db-configmap.yaml --namespace $NAMESPACE + +echo "************************************" +echo "* Create env and deploy... *" +echo "************************************" + +echo ${ROCKETMQ_REPO}:${ROCKETMQ_VERSION}: ${NAMESPACE} deploy start + +echo "Deploying s3-localstack..." # deploy s3-localstack helm repo add localstack-charts https://localstack.github.io/helm-charts -helm install s3-localstack localstack-charts/localstack -f deploy/localstack_s3.yaml -# --kubeconfig ./config +helm install s3-localstack localstack-charts/localstack -f deploy/localstack_s3.yaml --namespace $NAMESPACE + +# Wait for s3-localstack to be ready +kubectl rollout status --watch --timeout=120s statefulset/s3-localstack --namespace $NAMESPACE +echo "Deploying MySQL..." # deploy mysql helm repo add bitnami https://charts.bitnami.com/bitnami +helm install mysql bitnami/mysql -f deploy/mysql.yaml --namespace $NAMESPACE + +# Wait for mysql to be ready +kubectl rollout status --watch --timeout=120s statefulset/mysql --namespace $NAMESPACE -helm install mysql bitnami/mysql -f deploy/mysql.yaml +echo "Deploying rocketmq..." # deploy rocketmq-on-s3 -helm install rocketmq-on-s3 ../rocketmq-k8s-helm/ -f deploy/helm_sample_values.yaml +helm install rocketmq-on-s3 . -f deploy/helm_sample_values.yaml --set image.repository=$ROCKETMQ_REPO --set image.tag=$ROCKETMQ_VERSION --namespace $NAMESPACE +kubectl rollout status --watch --timeout=360s statefulset/rocketmq-on-s3-broker --namespace $NAMESPACE +echo "Deployment successful!" \ No newline at end of file diff --git a/rocketmq-k8s-helm/deploy/configmap-template.yaml b/rocketmq-k8s-helm/deploy/configmap-template.yaml new file mode 100644 index 0000000..42a77fc --- /dev/null +++ b/rocketmq-k8s-helm/deploy/configmap-template.yaml @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: mysql-initdb-config +data: + initdb.sql: | + use metadata; diff --git a/rocketmq-k8s-helm/deploy/ddl.sql b/rocketmq-k8s-helm/deploy/ddl.sql index adf6030..0edb9b0 100644 --- a/rocketmq-k8s-helm/deploy/ddl.sql +++ b/rocketmq-k8s-helm/deploy/ddl.sql @@ -46,6 +46,7 @@ CREATE TABLE IF NOT EXISTS topic id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL, queue_num INT NOT NULL DEFAULT 0, + retention_hours INT NOT NULL DEFAULT 72, status TINYINT DEFAULT 0, create_time DATETIME DEFAULT current_timestamp, update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, diff --git a/rocketmq-k8s-helm/deploy/helm_sample_values.yaml b/rocketmq-k8s-helm/deploy/helm_sample_values.yaml index 8900f07..a17f1ea 100644 --- a/rocketmq-k8s-helm/deploy/helm_sample_values.yaml +++ b/rocketmq-k8s-helm/deploy/helm_sample_values.yaml @@ -28,6 +28,6 @@ broker: db: - url: "jdbc:mysql://10.1.0.119:3306/metadata" + url: "jdbc:mysql://mysql:3306/metadata" userName: "root" - password: "root" + password: "passward" diff --git a/rocketmq-k8s-helm/deploy/init-db-configmap.yaml b/rocketmq-k8s-helm/deploy/init-db-configmap.yaml new file mode 100644 index 0000000..cc8e623 --- /dev/null +++ b/rocketmq-k8s-helm/deploy/init-db-configmap.yaml @@ -0,0 +1,200 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: mysql-initdb-config +data: + initdb.sql: | + use metadata; + /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + CREATE TABLE IF NOT EXISTS lease + ( + node_id INT NOT NULL, + epoch INT NOT NULL DEFAULT 0, + expiration_time DATETIME NOT NULL + ); + + INSERT INTO lease(node_id, epoch, expiration_time) + VALUES (0, 0, TIMESTAMP('2023-01-01')); + + CREATE TABLE IF NOT EXISTS node + ( + id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + instance_id VARCHAR(255), + volume_id VARCHAR(255), + hostname VARCHAR(255), + vpc_id VARCHAR(255), + address VARCHAR(255) NOT NULL, + epoch INT NOT NULL DEFAULT 0, + create_time DATETIME DEFAULT CURRENT_TIMESTAMP, + update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + UNIQUE INDEX idx_name (name), + UNIQUE INDEX idx_host_name (hostname), + UNIQUE INDEX idx_address (address) + ); + + CREATE TABLE IF NOT EXISTS topic + ( + id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + queue_num INT NOT NULL DEFAULT 0, + retention_hours INT NOT NULL DEFAULT 72, + status TINYINT DEFAULT 0, + create_time DATETIME DEFAULT current_timestamp, + update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + accept_message_types TEXT NOT NULL, + UNIQUE INDEX idx_topic_name (name) + ); + + CREATE TABLE IF NOT EXISTS queue_assignment + ( + topic_id BIGINT NOT NULL, + queue_id INT NOT NULL, + src_node_id INT NOT NULL, + dst_node_id INT NOT NULL, + status TINYINT NOT NULL, + create_time DATETIME DEFAULT CURRENT_TIMESTAMP, + update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + ); + + CREATE TABLE IF NOT EXISTS stream + ( + id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, + topic_id BIGINT NOT NULL, + queue_id INT NOT NULL, + stream_role TINYINT NOT NULL DEFAULT 0, + group_id BIGINT NULL, + src_node_id INT, + dst_node_id INT, + epoch BIGINT NOT NULL DEFAULT -1, + range_id INT NOT NULL DEFAULT -1, + start_offset BIGINT NOT NULL DEFAULT 0, + state INT NOT NULL DEFAULT 1, + create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + UNIQUE INDEX idx_queue (topic_id, queue_id, group_id, stream_role) + ); + + CREATE TABLE IF NOT EXISTS consumer_group + ( + id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + status TINYINT NOT NULL DEFAULT 0, + dead_letter_topic_id BIGINT, + max_delivery_attempt INT NOT NULL DEFAULT 16, + group_type TINYINT NOT NULL, + create_time DATETIME DEFAULT CURRENT_TIMESTAMP, + update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + UNIQUE INDEX idx_name (name) + ); + + CREATE TABLE IF NOT EXISTS subscription + ( + id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, + group_id BIGINT NOT NULL, + topic_id BIGINT NOT NULL, + expression VARCHAR(255) NOT NULL, + create_time DATETIME DEFAULT CURRENT_TIMESTAMP, + update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + UNIQUE INDEX idx_subscription_group_topic (group_id, topic_id) + ); + + CREATE TABLE IF NOT EXISTS group_progress + ( + group_id BIGINT NOT NULL, + topic_id BIGINT NOT NULL, + queue_id INT NOT NULL, + queue_offset BIGINT NOT NULL, + UNIQUE INDEX idx_group_progress (group_id, topic_id, queue_id) + ); + + CREATE TABLE IF NOT EXISTS `range` + ( + id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, + range_id INT NOT NULL, + stream_id BIGINT NOT NULL, + epoch BIGINT NOT NULL, + start_offset BIGINT NOT NULL, + end_offset BIGINT NOT NULL, + node_id INT NOT NULL, + UNIQUE INDEX idx_stream_range (stream_id, range_id), + INDEX idx_stream_start_offset (stream_id, start_offset) + ); + + CREATE TABLE IF NOT EXISTS s3object + ( + id BIGINT NOT NULL PRIMARY KEY, + object_size BIGINT, + stream_id BIGINT, + prepared_timestamp TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + committed_timestamp TIMESTAMP(3), + expired_timestamp TIMESTAMP(3) NOT NULL, + marked_for_deletion_timestamp TIMESTAMP(3), + state TINYINT NOT NULL DEFAULT 1 + ); + + CREATE TABLE IF NOT EXISTS s3streamobject + ( + id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, + stream_id BIGINT NOT NULL, + start_offset BIGINT NOT NULL, + end_offset BIGINT NOT NULL, + object_id BIGINT NOT NULL, + object_size BIGINT NOT NULL, + base_data_timestamp BIGINT, + committed_timestamp BIGINT, + created_timestamp BIGINT, + UNIQUE INDEX uk_s3_stream_object_object_id (object_id), + INDEX idx_s3_stream_object_stream_id (stream_id, start_offset) + ); + + CREATE TABLE IF NOT EXISTS s3walobject + ( + object_id BIGINT NOT NULL, + object_size BIGINT NOT NULL, + node_id INT NOT NULL, + sequence_id BIGINT NOT NULL, + sub_streams LONGTEXT NOT NULL, -- immutable + base_data_timestamp BIGINT, + committed_timestamp BIGINT, + created_timestamp BIGINT, + UNIQUE INDEX uk_s3_wal_object_node_sequence_id (node_id, sequence_id), + INDEX idx_s3_wal_object_object_id (object_id) + ); + + CREATE TABLE IF NOT EXISTS sequence ( + name VARCHAR(255) NOT NULL, + next BIGINT NOT NULL DEFAULT 1, + UNIQUE INDEX idx_name(name) + ); + INSERT INTO sequence(name) VALUES ('S3_OBJECT_ID_SEQ'); \ No newline at end of file diff --git a/rocketmq-k8s-helm/deploy/localstack_s3.yaml b/rocketmq-k8s-helm/deploy/localstack_s3.yaml index bdbd73e..57997c8 100644 --- a/rocketmq-k8s-helm/deploy/localstack_s3.yaml +++ b/rocketmq-k8s-helm/deploy/localstack_s3.yaml @@ -1,8 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. enableStartupScripts: true service: - type: LoadBalancer + type: ClusterIP startupScriptContent: | #!/bin/bash diff --git a/rocketmq-k8s-helm/deploy/mysql.yaml b/rocketmq-k8s-helm/deploy/mysql.yaml index fd13385..cc5be12 100644 --- a/rocketmq-k8s-helm/deploy/mysql.yaml +++ b/rocketmq-k8s-helm/deploy/mysql.yaml @@ -1,5 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +global: + storageClass: "longhorn" + image: tag: 8.0.35 + auth: rootPassword: "passward" database: "metadata" @@ -8,9 +27,10 @@ service: type: LoadBalancer primary: - extraVolumeMounts: - - "/docker-entrypoint-initdb.d/ddl.sql": "./ddl.sql" -initdbScripts: - init_script.sh: | - #!/bin/sh - mysql -u root -p passward < ./ddl.sql + extraVolumeMounts: | + - name: init + mountPath: /docker-entrypoint-initdb.d/ + extraVolumes: | + - name: init + configMap: + name: mysql-initdb-config diff --git a/rocketmq-kubeblocks/.helmignore b/rocketmq-kubeblocks/.helmignore new file mode 100644 index 0000000..d8a5320 --- /dev/null +++ b/rocketmq-kubeblocks/.helmignore @@ -0,0 +1,38 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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/ diff --git a/rocketmq-kubeblocks/Chart.yaml b/rocketmq-kubeblocks/Chart.yaml new file mode 100644 index 0000000..39e052b --- /dev/null +++ b/rocketmq-kubeblocks/Chart.yaml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +apiVersion: v2 +name: rocketmq-k8s-helm +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: 5.1.3 + +# 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.1.3" diff --git a/rocketmq-kubeblocks/templates/broker/NOTES.txt b/rocketmq-kubeblocks/templates/broker/NOTES.txt new file mode 100644 index 0000000..0a6fe66 --- /dev/null +++ b/rocketmq-kubeblocks/templates/broker/NOTES.txt @@ -0,0 +1 @@ +1. Get the application URL by running these commands: \ No newline at end of file diff --git a/rocketmq-kubeblocks/templates/broker/_brokerconfig.tpl b/rocketmq-kubeblocks/templates/broker/_brokerconfig.tpl new file mode 100644 index 0000000..335586c --- /dev/null +++ b/rocketmq-kubeblocks/templates/broker/_brokerconfig.tpl @@ -0,0 +1,60 @@ +{{/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*/}} + +{{- define "rocketmq-broker.config" -}} +{{- $name := include "rocketmq-broker.fullname" . }} +{{- $clusterName := include "rocketmq-broker.clusterName" . }} +{{- $brokerNamePrefix := include "rocketmq-broker.brokerNamePrefix" . }} +{{- $config := .Values.broker.config }} +{{- $s3stream := .Values.broker.s3stream }} +{{- $bindAddress := .Values.broker.service }} +{{- $innerKey := .Values.broker.inner }} +{{- $db := .Values.broker.db }} +{{- $replicaCount := .Values.broker.replicaCount | int }} +{{- range $index := until $replicaCount }} + {{ $clusterName }}-{{ $name }}-{{ $index }}: | + name: {{ $clusterName }}-{{ $name }}-{{ $index }} + instanceId: {{ $brokerNamePrefix }}-{{ $index }} + bindAddress: "0.0.0.0:{{ $bindAddress.port }}" + innerAccessKey: {{ $innerKey.accessKey }} + innerSecretKey: {{ $innerKey.secretKey }} + s3Stream: + s3WALPath: {{ $s3stream.s3WALPath }} + s3Endpoint: {{ $s3stream.s3Endpoint }} + s3Bucket: {{ $s3stream.s3Bucket }} + s3Region: {{ $s3stream.s3Region }} + s3ForcePathStyle: {{ $s3stream.s3ForcePathStyle }} + s3AccessKey: {{ $s3stream.s3AccessKey }} + s3SecretKey: {{ $s3stream.s3SecretKey }} + db: + url: {{ $db.url }} + userName: {{ $db.userName }} + password: {{ $db.password }} + metrics: + exporterType: "OTLP_GRPC" + grpcExporterTarget: "http://10.129.63.127:4317" + grpcExporterHeader: "" + grpcExporterTimeOutInMills: 31000 + periodicExporterIntervalInMills: 30000 + promExporterPort: 5557 + promExporterHost: "localhost" + labels: "" + exportInDelta: false +{{ $config | indent 4 }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/rocketmq-kubeblocks/templates/broker/_helpers.tpl b/rocketmq-kubeblocks/templates/broker/_helpers.tpl new file mode 100644 index 0000000..5c193c9 --- /dev/null +++ b/rocketmq-kubeblocks/templates/broker/_helpers.tpl @@ -0,0 +1,89 @@ +{{/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*/}} + +{{/* +Expand the name of the chart. +*/}} +{{- define "rocketmq-broker.name" -}} +{{- default .Chart.Name .Values.broker.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-broker.fullname" -}} +{{- if .Values.broker.fullnameOverride }} +{{- .Values.broker.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.broker.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-broker.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "rocketmq-broker.labels" -}} +{{ include "rocketmq-broker.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "rocketmq-broker.selectorLabels" -}} +app.kubernetes.io/name: {{ include "rocketmq-broker.fullname" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/cluster: {{ include "rocketmq-broker.clusterName" . }} +{{- end }} + +{{- define "rocketmq-broker.clusterName" -}} +{{- if .Values.broker.conf.clusterNameOverride }} +{{- .Values.broker.conf.clusterNameOverride | trunc 63 | trimSuffix "-" }} +{{- else -}} +DefaultCluster +{{- end }} +{{- end }} + +{{- define "rocketmq-broker.brokerNamePrefix" -}} +{{- if .Values.broker.conf.brokerNamePrefixOverride }} +{{- .Values.broker.conf.brokerNamePrefixOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- include "rocketmq-broker.fullname" . }} +{{- end }} +{{- end }} + +{{- define "rocketmq-broker.brokerImage" -}} +{{ .Values.broker.image.repository }}:{{ .Values.broker.image.tag | default .Chart.AppVersion }} +{{- end }} \ No newline at end of file diff --git a/rocketmq-k8s-helm/cluster-kb/clusterdefinition.yaml b/rocketmq-kubeblocks/templates/broker/clusterdefinition.yaml similarity index 100% rename from rocketmq-k8s-helm/cluster-kb/clusterdefinition.yaml rename to rocketmq-kubeblocks/templates/broker/clusterdefinition.yaml diff --git a/rocketmq-k8s-helm/cluster-kb/clusterversion.yaml b/rocketmq-kubeblocks/templates/broker/clusterversion.yaml similarity index 100% rename from rocketmq-k8s-helm/cluster-kb/clusterversion.yaml rename to rocketmq-kubeblocks/templates/broker/clusterversion.yaml diff --git a/rocketmq-kubeblocks/templates/broker/configmap.yaml b/rocketmq-kubeblocks/templates/broker/configmap.yaml new file mode 100644 index 0000000..fab2308 --- /dev/null +++ b/rocketmq-kubeblocks/templates/broker/configmap.yaml @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: broker-conf + labels: + {{- include "rocketmq-broker.labels" . | nindent 4 }} +data: +{{- include "rocketmq-broker.config" . }} \ No newline at end of file diff --git a/rocketmq-kubeblocks/templates/broker/service.yaml b/rocketmq-kubeblocks/templates/broker/service.yaml new file mode 100644 index 0000000..c38a3fe --- /dev/null +++ b/rocketmq-kubeblocks/templates/broker/service.yaml @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: Service +metadata: + name: {{ include "rocketmq-broker.fullname" . }} + labels: + {{- include "rocketmq-broker.labels" . | nindent 4 }} +spec: + ports: + - port: {{ .Values.broker.service.port }} + targetPort: broker-port + protocol: TCP + name: broker-port + selector: + {{- include "rocketmq-broker.selectorLabels" . | nindent 4 }} + clusterIP: None \ No newline at end of file diff --git a/rocketmq-kubeblocks/templates/broker/statefulset.yaml b/rocketmq-kubeblocks/templates/broker/statefulset.yaml new file mode 100644 index 0000000..8051ee7 --- /dev/null +++ b/rocketmq-kubeblocks/templates/broker/statefulset.yaml @@ -0,0 +1,99 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "rocketmq-broker.fullname" . }} +spec: + replicas: {{ .Values.broker.replicaCount }} + serviceName: {{ include "rocketmq-broker.fullname" . }} + selector: + matchLabels: + {{- include "rocketmq-broker.selectorLabels" . | nindent 6 }} + podManagementPolicy: Parallel + updateStrategy: + type: RollingUpdate + template: + metadata: + labels: + {{- include "rocketmq-broker.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: broker + image: {{ include "rocketmq-broker.brokerImage" . }} + {{- if $.Values.broker.image.pullPolicy }} + imagePullPolicy: {{ $.Values.broker.image.pullPolicy }} + {{- end }} + command: [ "/bin/sh" ] + args: [ "-c", "./run-server.sh com.automq.rocketmq.broker.BrokerStartup -c /home/rocketmq/rocketmq-on-s3-5.1.3/conf/broker/$(CLUSTER_NAME)-$(POD_NAME)" ] + env: + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: CLUSTER_NAME + valueFrom: + fieldRef: + fieldPath: metadata.labels['app.kubernetes.io/cluster'] + - name: INSTANCE_NAME + valueFrom: + fieldRef: + fieldPath: metadata.labels['app.kubernetes.io/name'] + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: BROKER_MEM + value: {{ .Values.broker.jvmMemory }} + ports: + - name: broker + containerPort: {{ .Values.broker.service.port }} + protocol: TCP + readinessProbe: + failureThreshold: 3 + initialDelaySeconds: 60 + periodSeconds: 15 + successThreshold: 1 + tcpSocket: + port: {{ .Values.broker.service.port }} + timeoutSeconds: 1 + livenessProbe: + failureThreshold: 3 + initialDelaySeconds: 60 + periodSeconds: 15 + successThreshold: 1 + tcpSocket: + port: {{ .Values.broker.service.port }} + timeoutSeconds: 1 + resources: + {{- toYaml .Values.broker.resources | nindent 12 }} + volumeMounts: + - mountPath: /home/rocketmq/rocketmq-on-s3-5.1.3/conf/broker + name: broker-config + - mountPath: /root/logs/rocketmqlogs + name: broker-storage + {{- with .Values.broker.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: broker-config + configMap: + name: broker-conf + - name: broker-storage + hostPath: + path: /root/logs/rocketmqlogs + type: DirectoryOrCreate diff --git a/rocketmq-kubeblocks/values.yaml b/rocketmq-kubeblocks/values.yaml new file mode 100644 index 0000000..88ff3c7 --- /dev/null +++ b/rocketmq-kubeblocks/values.yaml @@ -0,0 +1,78 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default values for rocketmq-k8s-helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +broker: + namespace: default + replicaCount: 1 + image: + pullPolicy: Always + repository: "automqinc/rocketmq_e2e" + tag: "5.1.3-alpine" + + partition: 0 + persistence: + enabled: false + size: 8Gi + + nameOverride: "broker" + fullnameOverride: "" + namesrvAddr: "" + + conf: + clusterNameOverride: "" + brokerNamePrefixOverride: "" + + config: "" + + service: + port: 8081 + + jvmMemory: " -Xms4g -Xmx4g -Xmn2g -XX:MaxDirectMemorySize=8g " + resources: + limits: + cpu: 2 + memory: 4Gi + requests: + cpu: 2 + memory: 4Gi + + nodeSelector: { } + + tolerations: [ ] + + inner: + accessKey: "aa" + secretKey: "bb" + + s3stream: + s3WALPath: "/tmp/s3rocketmq/wal" + s3Endpoint: "http://minio.hellocorp.test" + s3Bucket: "wxy" + s3Region: "us-east-1" + s3ForcePathStyle: true + s3AccessKey: "Y6pKg2MmFL3wlWiEJEtc" + s3SecretKey: "eTWpQEutpExoYXebV8D1HXJ8TwDWyoKoAVJpX32K" + + + db: + url: "jdbc:mysql://mysql-server:3306/metadata" + userName: "root" + password: "password" + +