diff --git a/addons/redis-cluster/templates/_helpers.tpl b/addons/redis-cluster/templates/_helpers.tpl index 54c515882..d8a247bf0 100644 --- a/addons/redis-cluster/templates/_helpers.tpl +++ b/addons/redis-cluster/templates/_helpers.tpl @@ -1,3 +1,29 @@ +{{/* +Define common fileds of cluster object +*/}} +{{- define "redis-cluster.clusterCommonWithNodePort" }} +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: Cluster +metadata: + name: {{ include "kblib.clusterName" . }} + namespace: {{ .Release.Namespace }} + labels: {{ include "kblib.clusterLabels" . | nindent 4 }} + annotations: + {{ include "redis-cluster.nodeportFeatureGate" . | nindent 4 }} +spec: + clusterVersionRef: {{ .Values.version }} + terminationPolicy: {{ .Values.extra.terminationPolicy }} + {{- include "kblib.affinity" . | indent 2 }} +{{- end }} + +{{/* +Define redis cluster annotation keys for nodeport feature gate. +*/}} +{{- define "redis-cluster.nodeportFeatureGate" -}} +kubeblocks.io/enabled-node-port-svc: redis,redis-sentinel +kubeblocks.io/enabled-pod-ordinal-svc: redis,redis-sentinel +{{- end }} + {{/* Define redis cluster sentinel component. */}} @@ -40,24 +66,6 @@ Define redis cluster twemproxy component. memory: {{ print .Values.twemproxy.memory "Gi" | quote }} {{- end }} -{{/* -Define redis cluster sentinel nodeport service. -*/}} -{{- define "redis-cluster.sentinel-nodeport" }} -- name: redis-sentinel-nodeport - serviceName: redis-sentinel-nodeport - generatePodOrdinalService: true - componentSelector: redis-sentinel - spec: - type: NodePort - ports: - - name: redis-sentinel-nodeport - port: 26379 - targetPort: 26379 -{{- end }} - -{{/* -Define redis cluster sentinel component. */}} {{- define "redis-cluster.sentinelCompDef" }} - componentDef: redis-sentinel diff --git a/addons/redis-cluster/templates/cluster.yaml b/addons/redis-cluster/templates/cluster.yaml index 39f4ec25c..74aad2de9 100644 --- a/addons/redis-cluster/templates/cluster.yaml +++ b/addons/redis-cluster/templates/cluster.yaml @@ -22,25 +22,12 @@ {{- if and (eq .Values.mode "replication") .Values.sentinel.enabled }} {{- include "redis-cluster.sentinel" . | indent 4 }} {{- end }} +{{- else if .Values.nodePortEnabled }} +{{- include "redis-cluster.clusterCommonWithNodePort" . }} {{- else }} {{- include "kblib.clusterCommon" . }} +{{- end }} clusterDefinitionRef: redis # ref clusterDefinition.name - {{- if .Values.nodePortEnabled }} - services: - - name: redis-nodeport - serviceName: redis-nodeport - generatePodOrdinalService: true - componentSelector: redis - spec: - type: NodePort - ports: - - name: redis-nodeport - port: 6379 - targetPort: 6379 - {{- if and (eq .Values.mode "replication") .Values.sentinel.enabled }} - {{- include "redis-cluster.sentinel-nodeport" . | indent 4 }} - {{- end }} - {{- end }} componentSpecs: - name: redis componentDef: redis @@ -56,5 +43,4 @@ {{- include "kblib.componentServices" . | indent 6 }} {{- if and (eq .Values.mode "replication") .Values.sentinel.enabled }} {{- include "redis-cluster.sentinelCompDef" . | indent 4 }} - {{- end }} -{{- end }} \ No newline at end of file + {{- end }} \ No newline at end of file diff --git a/addons/redis/templates/componentdefinition-redis-sentinel.yaml b/addons/redis/templates/componentdefinition-redis-sentinel.yaml index c80ef9ea4..a0e750709 100644 --- a/addons/redis/templates/componentdefinition-redis-sentinel.yaml +++ b/addons/redis/templates/componentdefinition-redis-sentinel.yaml @@ -17,6 +17,15 @@ spec: - name: redis-sentinel port: 26379 targetPort: redis-sentinel + - name: redis-sentinel-nodeport + serviceName: redis-sentinel-nodeport + generatePodOrdinalService: true + spec: + type: NodePort + ports: + - name: redis-sentinel-nodeport + port: 26379 + targetPort: 26379 updateStrategy: BestEffortParallel volumes: - name: data diff --git a/addons/redis/templates/componentdefinition-redis.yaml b/addons/redis/templates/componentdefinition-redis.yaml index 4a9015726..9ed8e9838 100644 --- a/addons/redis/templates/componentdefinition-redis.yaml +++ b/addons/redis/templates/componentdefinition-redis.yaml @@ -18,6 +18,15 @@ spec: port: 6379 targetPort: redis roleSelector: primary + - name: redis-nodeport + serviceName: redis-nodeport + generatePodOrdinalService: true + spec: + type: NodePort + ports: + - name: redis-nodeport + port: 6379 + targetPort: redis updateStrategy: BestEffortParallel volumes: - name: data @@ -91,7 +100,7 @@ spec: optional: true nodePort: name: redis-nodeport - option: Optional + option: Required ## if the redis Service with name suffix redis-nodeport-{0,1...} is set, the REDIS_NODE_PORT_SVC_NAME_{0,1...} will be available - name: REDIS_NODE_PORT_SVC_NAME valueFrom: @@ -100,7 +109,7 @@ spec: name: redis-nodeport generatePodOrdinalServiceVar: true optional: true - host: Optional + host: Required ## the username of redis sentinel for redis connection, it is optional - name: SENTINEL_USER valueFrom: