Skip to content

Commit

Permalink
chore: adapt rabbitmq addon for API v1.0 (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuriwuyun authored Oct 25, 2024
1 parent 8f28d4b commit 9a78520
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 88 deletions.
8 changes: 0 additions & 8 deletions addons/rabbitmq/config/rabbitmq-env.tpl

This file was deleted.

56 changes: 3 additions & 53 deletions addons/rabbitmq/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/}}
Expand Down Expand Up @@ -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 -}}
15 changes: 9 additions & 6 deletions addons/rabbitmq/templates/_names.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

{{/*
Expand Down
13 changes: 13 additions & 0 deletions addons/rabbitmq/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions addons/rabbitmq/templates/componentdefinition.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion addons/rabbitmq/templates/componentversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
spec:
compatibilityRules:
- compDefs:
- {{ include "rabbitmq.componentDefName" . }}
- {{ include "rabbitmq.cmpdNamePrefix" . }}
releases:
- 3.13.2
- 3.12.14
Expand Down
13 changes: 0 additions & 13 deletions addons/rabbitmq/templates/scriptstemplate.yaml

This file was deleted.

4 changes: 1 addition & 3 deletions addons/rabbitmq/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ image:
componentServiceVersion:
rabbitmq: 3.13.2

clusterVersionOverride: ""
nameOverride: ""
fullnameOverride: ""

## Authentication parameters
##
Expand Down Expand Up @@ -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"

0 comments on commit 9a78520

Please sign in to comment.