Skip to content

Commit

Permalink
chore: remove redis cluster nodeport service and defined in component…
Browse files Browse the repository at this point in the history
… definition (#181)

(cherry picked from commit 72dec3a)
  • Loading branch information
Y-Rookie committed Jan 3, 2024
1 parent bdd5649 commit 0767d9d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 38 deletions.
44 changes: 26 additions & 18 deletions addons/redis-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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.
*/}}
Expand Down Expand Up @@ -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
Expand Down
22 changes: 4 additions & 18 deletions addons/redis-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions addons/redis/templates/componentdefinition-redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 0767d9d

Please sign in to comment.