From 9a78520c397662729527c49e2991bef4cb0bc263 Mon Sep 17 00:00:00 2001 From: xuriwuyun Date: Fri, 25 Oct 2024 17:08:11 +0800 Subject: [PATCH] chore: adapt rabbitmq addon for API v1.0 (#1107) --- addons/rabbitmq/config/rabbitmq-env.tpl | 8 --- addons/rabbitmq/templates/_helpers.tpl | 56 +------------------ addons/rabbitmq/templates/_names.tpl | 15 +++-- .../rabbitmq/templates/clusterdefinition.yaml | 13 +++++ .../templates/componentdefinition.yaml | 10 ++-- .../rabbitmq/templates/componentversion.yaml | 2 +- .../rabbitmq/templates/scriptstemplate.yaml | 13 ----- addons/rabbitmq/values.yaml | 4 +- 8 files changed, 33 insertions(+), 88 deletions(-) delete mode 100644 addons/rabbitmq/config/rabbitmq-env.tpl create mode 100644 addons/rabbitmq/templates/clusterdefinition.yaml delete mode 100644 addons/rabbitmq/templates/scriptstemplate.yaml diff --git a/addons/rabbitmq/config/rabbitmq-env.tpl b/addons/rabbitmq/config/rabbitmq-env.tpl deleted file mode 100644 index 4faed7ad7..000000000 --- a/addons/rabbitmq/config/rabbitmq-env.tpl +++ /dev/null @@ -1,8 +0,0 @@ -{{- $rabbitmq_port_info := getPortByName ( index $.podSpec.containers 0 ) "amqp" }} - -## for rabbitmq port -{{- $rabbitmq_port := 5672 }} -{{- if $rabbitmq_port_info }} - {{- $rabbitmq_port = $rabbitmq_port_info.containerPort }} -{{- end }} -SERVICE_PORT: {{ $rabbitmq_port }} diff --git a/addons/rabbitmq/templates/_helpers.tpl b/addons/rabbitmq/templates/_helpers.tpl index 0699a8c57..7b37f26fe 100644 --- a/addons/rabbitmq/templates/_helpers.tpl +++ b/addons/rabbitmq/templates/_helpers.tpl @@ -5,24 +5,6 @@ Expand the name of the chart. {{- 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 "rabbitmq.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. */}} @@ -51,41 +33,9 @@ app.kubernetes.io/name: {{ include "rabbitmq.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} - {{/* -Return rabbitmq service port +Common annotations */}} -{{- define "rabbitmq.service.port" -}} -{{- .Values.primary.service.ports.rabbitmq -}} -{{- end -}} - -{{/* -Get the password key. -*/}} -{{- define "rabbitmq.password" -}} -{{- if or (.Release.IsInstall) (not (lookup "apps.kubeblocks.io/v1alpha1" "ClusterDefinition" "" "rabbitmq")) -}} -{{ .Values.auth.password | default "$(RANDOM_PASSWD)"}} -{{- else -}} -{{ index (lookup "apps.kubeblocks.io/v1alpha1" "ClusterDefinition" "" "rabbitmq").spec.connectionCredential "password"}} -{{- end }} +{{- define "rabbitmq.annotations" -}} +helm.sh/resource-policy: keep {{- end }} - -{{/* -Check if cluster version is enabled, if enabledClusterVersions is empty, return true, -otherwise, check if the cluster version is in the enabledClusterVersions list, if yes, return true, -else return false. -Parameters: cvName, values -*/}} -{{- define "rabbitmq.isClusterVersionEnabled" -}} -{{- $cvName := .cvName -}} -{{- $enabledClusterVersions := .values.enabledClusterVersions -}} -{{- if eq (len $enabledClusterVersions) 0 -}} - {{- true -}} -{{- else -}} - {{- range $enabledClusterVersions -}} - {{- if eq $cvName . -}} - {{- true -}} - {{- end -}} - {{- end -}} -{{- end -}} -{{- end -}} diff --git a/addons/rabbitmq/templates/_names.tpl b/addons/rabbitmq/templates/_names.tpl index 39c8d0410..cdff28f85 100644 --- a/addons/rabbitmq/templates/_names.tpl +++ b/addons/rabbitmq/templates/_names.tpl @@ -10,14 +10,17 @@ rabbitmq {{- end -}} {{/* -Define component definition name +Define rabbitmq component definition name prefix */}} -{{- define "rabbitmq.componentDefName" -}} -{{- if eq (len .Values.resourceNamePrefix) 0 -}} -rabbitmq -{{- else -}} -{{- .Values.resourceNamePrefix -}} +{{- define "rabbitmq.cmpdNamePrefix" -}} +{{- default "rabbitmq" .Values.resourceNamePrefix -}}- {{- end -}} + +{{/* +Define rabbitmq component definition name +*/}} +{{- define "rabbitmq.cmpdName" -}} +{{ include "rabbitmq.cmpdNamePrefix" . }}{{ .Chart.Version }} {{- end -}} {{/* diff --git a/addons/rabbitmq/templates/clusterdefinition.yaml b/addons/rabbitmq/templates/clusterdefinition.yaml new file mode 100644 index 000000000..cbedebf90 --- /dev/null +++ b/addons/rabbitmq/templates/clusterdefinition.yaml @@ -0,0 +1,13 @@ +apiVersion: apps.kubeblocks.io/v1 +kind: ClusterDefinition +metadata: + name: rabbitmq + labels: + {{- include "rabbitmq.labels" . | nindent 4 }} +spec: + topologies: + - name: clustermode + components: + - name: rabbitmq + compDef: {{ include "rabbitmq.cmpdNamePrefix" . }} + default: true diff --git a/addons/rabbitmq/templates/componentdefinition.yaml b/addons/rabbitmq/templates/componentdefinition.yaml index 74c9db61e..a63343286 100644 --- a/addons/rabbitmq/templates/componentdefinition.yaml +++ b/addons/rabbitmq/templates/componentdefinition.yaml @@ -1,9 +1,11 @@ apiVersion: apps.kubeblocks.io/v1 kind: ComponentDefinition metadata: - name: {{ include "rabbitmq.componentDefName" . }} + name: {{ include "rabbitmq.cmpdName" . }} labels: {{- include "rabbitmq.labels" . | nindent 4 }} + annotations: + {{- include "rabbitmq.annotations" . | nindent 4 }} spec: provider: kubeblocks.io description: RabbitMQ is a reliable and mature messaging and streaming broker. @@ -69,7 +71,7 @@ spec: - name: RABBITMQ_USE_LONGNAME value: "true" - name: RABBITMQ_NODENAME - value: rabbit@$(KB_POD_NAME).$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE) + value: rabbit@$(MY_POD_NAME).$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE) - name: K8S_HOSTNAME_SUFFIX value: .$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE) image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag }} @@ -119,14 +121,14 @@ spec: - name: RABBITMQ_DEFAULT_USER valueFrom: credentialVarRef: - compDef: {{ include "rabbitmq.componentDefName" . }} + compDef: {{ include "rabbitmq.cmpdName" . }} name: root optional: false username: Required - name: RABBITMQ_DEFAULT_PASS valueFrom: credentialVarRef: - compDef: {{ include "rabbitmq.componentDefName" . }} + compDef: {{ include "rabbitmq.cmpdName" . }} name: root optional: false password: Required diff --git a/addons/rabbitmq/templates/componentversion.yaml b/addons/rabbitmq/templates/componentversion.yaml index fe1f05dc3..9d22e46d3 100644 --- a/addons/rabbitmq/templates/componentversion.yaml +++ b/addons/rabbitmq/templates/componentversion.yaml @@ -7,7 +7,7 @@ metadata: spec: compatibilityRules: - compDefs: - - {{ include "rabbitmq.componentDefName" . }} + - {{ include "rabbitmq.cmpdNamePrefix" . }} releases: - 3.13.2 - 3.12.14 diff --git a/addons/rabbitmq/templates/scriptstemplate.yaml b/addons/rabbitmq/templates/scriptstemplate.yaml deleted file mode 100644 index db24c80f4..000000000 --- a/addons/rabbitmq/templates/scriptstemplate.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: rabbitmq-scripts - labels: - {{- include "rabbitmq.labels" . | nindent 4 }} -data: - rabbitmq-setup.sh: |- - #!/bin/sh - - PORT=27018 - CONFIG_SVR_NAME=$KB_CLUSTER_NAME"-configsvr" - DOMAIN=$CONFIG_SVR_NAME"-headless."$KB_NAMESPACE".svc.cluster.local" diff --git a/addons/rabbitmq/values.yaml b/addons/rabbitmq/values.yaml index 481a04843..c556e63a9 100644 --- a/addons/rabbitmq/values.yaml +++ b/addons/rabbitmq/values.yaml @@ -12,9 +12,7 @@ image: componentServiceVersion: rabbitmq: 3.13.2 -clusterVersionOverride: "" nameOverride: "" -fullnameOverride: "" ## Authentication parameters ## @@ -48,4 +46,4 @@ enabledClusterVersions: [ ] ## @param resourceNamePrefix Prefix for all resources name created by this chart, that can avoid name conflict ## if you install multiple releases of this chart. ## If specified, the cluster definition will use it as name. -resourceNamePrefix: "" +resourceNamePrefix: "rabbitmq"