Skip to content

Commit

Permalink
chore: redis addon supports multiVersion defined with chartVersion (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie authored Sep 18, 2024
1 parent b94ad46 commit 5ace0d8
Show file tree
Hide file tree
Showing 21 changed files with 299 additions and 189 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ KubeBlocks add-ons.
| loki | loki-1.0.0 | Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus. It is designed to be very cost effective and easy to operate. | Chen-speculation |
| mariadb | mariadb-10.6.15 | MariaDB is a high performance open source relational database management system that is widely used for web and application servers | yinmin |
| milvus | milvus-v2.3.2 | A cloud-native vector database, storage for next generation AI applications. | leon-inf |
| minio | minio-1.0.0-alpha.0 | High Performance, Kubernetes Native Object Storage | fengluodb |
| minio | minio-2024.6.29 | High Performance, Kubernetes Native Object Storage | fengluodb |
| mogdb | mogdb-5.0.5 | A Helm chart for Kubernetes | yabinji shanshanying |
| mongodb | mongodb-4.0.28<br>mongodb-4.2.24<br>mongodb-4.4.29<br>mongodb-5.0.28<br>mongodb-6.0.16<br>mongodb-7.0.12 | MongoDB is a document database designed for ease of application development and scaling. | xuriwuyun |
| mysql | mysql-5.7.44<br>mysql-8.0.33<br>mysql-8.4.2<br>mysql-orc-5.7.44<br>mysql-orc-8.0.33<br>mysql-proxysql-2.4.4 | MySQL is a widely used, open-source relational database management system (RDBMS) | xuriwuyun |
Expand Down
231 changes: 157 additions & 74 deletions addons/redis/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,121 +6,205 @@ Expand the name of the chart.
{{- end }}

{{/*
Define redis component definition name
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 "redis.componentDefName" -}}
{{- if eq (len .Values.compDefinitionVersion.redis) 0 -}}
redis
{{- else -}}
{{- printf "redis-%s" .Values.compDefinitionVersion.redis -}}
{{- define "redis.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 "redis.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Common annotations
*/}}
{{- define "redis.annotations" -}}
helm.sh/resource-policy: keep
{{- end }}

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

{{/*
Define redis component definition regular expression name prefix
*/}}
{{- define "redis.cmpdRegexpPattern" -}}
^redis-\d+
{{- end -}}

{{/*
Define redis 7.X component definition regular expression name prefix
*/}}
{{- define "redis7.cmpdRegexpPattern" -}}
^redis-7.*
{{- end -}}

{{/*
Define redis component definition name prefix
Define redis sentienl component definition regular expression name prefix
*/}}
{{- define "redis.componentDefNamePrefix" -}}
{{- printf "redis-%s" .Values.compDefinitionVersion.redis -}}
{{- define "redisSentinel.cmpdRegexpPattern" -}}
^redis-sentinel-\d+
{{- end -}}

{{/*
Define redis-sentinel component definition name
Define redis sentienl 7.X component definition regular expression name prefix
*/}}
{{- define "redis-sentinel.componentDefName" -}}
{{- if eq (len .Values.compDefinitionVersion.sentinel) 0 -}}
redis-sentinel
{{- else -}}
{{- printf "redis-sentinel-%s" .Values.compDefinitionVersion.sentinel -}}
{{- define "redisSentinel7.cmpdRegexpPattern" -}}
^redis-sentinel-7.*
{{- end -}}

{{/*
Define redis cluster component definition regular expression name prefix
*/}}
{{- define "redisCluster.cmpdRegexpPattern" -}}
^redis-cluster-\d+
{{- end -}}

{{/*
Define redis-sentinel component definition name prefix
Define redis cluster 7.X component definition regular expression name prefix
*/}}
{{- define "redis-sentinel.componentDefNamePrefix" -}}
{{- printf "redis-sentinel-%s" .Values.compDefinitionVersion.sentinel -}}
{{- define "redisCluster7.cmpdRegexpPattern" -}}
^redis-cluster-7.*
{{- end -}}

{{/*
Define redis-cluster component definition name
Define redis twemproxy component definition regular expression name prefix
*/}}
{{- define "redis-cluster.componentDefName" -}}
{{- if eq (len .Values.compDefinitionVersion.redisCluster) 0 -}}
redis-cluster
{{- define "redisTwemproxy.cmpdRegexpPattern" -}}
^redis-twemproxy-\d+
{{- end -}}

{{/*
Define redis twemproxy 0.5.X component definition regular expression name prefix
*/}}
{{- define "redisTwemproxy05.cmpdRegexpPattern" -}}
^redis-twemproxy-0\.5.*
{{- end -}}

{{/*
Define redis 7.X component definition name
*/}}
{{- define "redis7.cmpdName" -}}
{{- if eq (len .Values.cmpdVersionPrefix.redis.major7.minorAll ) 0 -}}
redis-7-{{ .Chart.Version }}
{{- else -}}
{{- printf "redis-cluster-%s" .Values.compDefinitionVersion.redisCluster -}}
{{- printf "%s" .Values.cmpdVersionPrefix.redis.major7.minorAll -}}-{{ .Chart.Version }}
{{- end -}}
{{- end -}}

{{/*
Define redis-cluster component definition name prefix
Define redis sentinel 7.X component definition name
*/}}
{{- define "redis-cluster.componentDefNamePrefix" -}}
{{- printf "redis-cluster-%s" .Values.compDefinitionVersion.redisCluster -}}
{{- define "redisSentinel7.cmpdName" -}}
{{- if eq (len .Values.cmpdVersionPrefix.redisSentinel.major7.minorAll ) 0 -}}
redis-sentinel-7-{{ .Chart.Version }}
{{- else -}}
{{- printf "%s" .Values.cmpdVersionPrefix.redisSentinel.major7.minorAll -}}-{{ .Chart.Version }}
{{- end -}}
{{- end -}}

{{/*
Define redis-twemproxy component definition name
Define redis-cluster 7.X component definition name
*/}}
{{- define "redis-twemproxy.componentDefName" -}}
{{- if eq (len .Values.compDefinitionVersion.twemproxy) 0 -}}
redis-twemproxy
{{- define "redisCluster7.cmpdName" -}}
{{- if eq (len .Values.cmpdVersionPrefix.redisCluster.major7.minorAll ) 0 -}}
redis-cluster-7-{{ .Chart.Version }}
{{- else -}}
{{- printf "redis-twemproxy-%s" .Values.compDefinitionVersion.twemproxy -}}
{{- printf "%s" .Values.cmpdVersionPrefix.redisCluster.major7.minorAll -}}-{{ .Chart.Version }}
{{- end -}}
{{- end -}}

{{/*
Define redis-twemproxy component definition name prefix
Define redis-twemproxy 0.5.X component definition name
*/}}
{{- define "redis-twemproxy.componentDefNamePrefix" -}}
{{- printf "redis-twemproxy-%s" .Values.compDefinitionVersion.twemproxy -}}
{{- define "redisTwemproxy05.cmpdName" -}}
{{- if eq (len .Values.cmpdVersionPrefix.redisTwemproxy.major05.minorAll ) 0 -}}
redis-twemproxy-0.5-{{ .Chart.Version }}
{{- else -}}
{{- printf "%s" .Values.cmpdVersionPrefix.redisTwemproxy.major05.minorAll -}}-{{ .Chart.Version }}
{{- end -}}
{{- 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 redis 7.X component configuration template name
*/}}
{{- define "redis.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 }}
{{- define "redis7.configurationTemplate" -}}
redis7-config-template-{{ .Chart.Version }}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
Define redis cluster component 7.X configuration template name
*/}}
{{- define "redis.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- define "redisCluster7.configurationTemplate" -}}
redis-cluster7-config-template-{{ .Chart.Version }}
{{- end -}}

{{/*
Common labels
Define redis 7.X component script template name
*/}}
{{- define "redis.labels" -}}
helm.sh/chart: {{ include "redis.chart" . }}
{{ include "redis.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{- define "redis7.scriptsTemplate" -}}
redis7-scripts-template-{{ .Chart.Version }}
{{- end -}}

{{/*
Selector labels
Define redis cluster 7.X component script template name
*/}}
{{- define "redis.selectorLabels" -}}
app.kubernetes.io/name: {{ include "redis.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- define "redisCluster7.scriptsTemplate" -}}
redis-cluster7-scripts-template-{{ .Chart.Version }}
{{- end -}}

{{/*
Define redis 7.X component config constraint name
*/}}
{{- define "redis7.configConstraint" -}}
redis7-config-constraints
{{- end -}}

{{/*
Define redis cluster 7.X component config constraint name
*/}}
{{- define "redisCluster7.configConstraint" -}}
redis-cluster7-config-constraints
{{- end -}}

{{/*
Define redis metrics config name
*/}}
{{- define "redis.metricsConfiguration" -}}
redis-metrics-config
{{- end -}}

{{/*
Define image
Expand All @@ -129,23 +213,23 @@ Define image
{{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}
{{- end }}

{{- define "redis.image" -}}
{{- define "redis7.image" -}}
{{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag.major7.minor72 }}
{{- end }}

{{- define "redis-sentinel.repository" -}}
{{- define "redisSentinel.repository" -}}
{{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}
{{- end }}

{{- define "redis-sentinel.image" -}}
{{- define "redisSentinel7.image" -}}
{{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag.major7.minor72 }}
{{- end }}

{{- define "redis-twemproxy.repository" -}}
{{- define "redisTwemproxy.repository" -}}
{{ .Values.redisTwemproxyImage.registry | default ( .Values.image.registry | default "docker.io" ) }}/{{ .Values.redisTwemproxyImage.repository }}
{{- end }}

{{- define "redis-twemproxy.image" -}}
{{- define "redisTwemproxy05.image" -}}
{{ .Values.redisTwemproxyImage.registry | default ( .Values.image.registry | default "docker.io" ) }}/{{ .Values.redisTwemproxyImage.repository }}:{{ .Values.redisTwemproxyImage.tag }}
{{- end }}

Expand All @@ -162,10 +246,9 @@ Define image
{{- end }}}

{{- define "apeDts.image" -}}
{{ .Values.image.apeDts.registry | default ( .Values.image.registry | default "docker.io" ) }}/{{ .Values.image.apeDts.repository}}:{{ .Values.image.apeDts.tag }}
{{ .Values.apeDtsImage.registry | default ( .Values.image.registry | default "docker.io" ) }}/{{ .Values.apeDtsImage.repository}}:{{ .Values.apeDtsImage.tag }}
{{- end }}}


{{/*
Generate scripts configmap
*/}}
Expand Down
10 changes: 5 additions & 5 deletions addons/redis/templates/backupactionset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
preBackup: []
postBackup: []
backupData:
image: {{ include "redis.image" . }}
image: {{ include "redis7.image" . }}
runOnTargetPodNode: true
syncProgress:
enabled: true
Expand All @@ -28,7 +28,7 @@ spec:
{{- .Files.Get "dataprotection/backup.sh" | nindent 8 }}
restore:
prepareData:
image: {{ include "redis.image" . }}
image: {{ include "redis7.image" . }}
command:
- bash
- -c
Expand Down Expand Up @@ -56,7 +56,7 @@ spec:
preBackup: []
postBackup: []
backupData:
image: {{ include "redis.image" . }}
image: {{ include "redis7.image" . }}
runOnTargetPodNode: true
syncProgress:
enabled: true
Expand Down Expand Up @@ -98,7 +98,7 @@ spec:
preBackup: []
postBackup: []
backupData:
image: {{ include "redis.image" . }}
image: {{ include "redis7.image" . }}
runOnTargetPodNode: true
syncProgress:
enabled: true
Expand All @@ -112,7 +112,7 @@ spec:
{{- .Files.Get "dataprotection/pitr-backup.sh" | nindent 8 }}
restore:
prepareData:
image: {{ include "redis.image" . }}
image: {{ include "redis7.image" . }}
command:
- bash
- -c
Expand Down
4 changes: 2 additions & 2 deletions addons/redis/templates/backuppolicytemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
spec:
backupPolicies:
- componentDefs:
- {{ include "redis.componentDefName" . }}
- {{ include "redis7.cmpdName" . }}
target:
role: secondary
fallbackRole: primary
Expand Down Expand Up @@ -49,7 +49,7 @@ spec:
cronExpression: "0 18 * * 0"
retentionPeriod: 7d
- componentDefs:
- {{ include "redis-cluster.componentDefName" . }}
- {{ include "redisCluster7.cmpdName" . }}
target:
role: secondary
fallbackRole: primary
Expand Down
Loading

0 comments on commit 5ace0d8

Please sign in to comment.