From 6515a2ec7d8b1ee3ca94086fa11299dc76cf15ba Mon Sep 17 00:00:00 2001 From: OpenGuidou Date: Thu, 2 Jan 2025 17:10:03 +0100 Subject: [PATCH] feat(redis-ha): Add tls ports to netpol if defined Signed-off-by: OpenGuidou --- .../templates/redis-ha-network-policy.yaml | 48 +++++++++++++++++ .../redis-haproxy-network-policy.yaml | 52 ++++++++++++++++--- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/charts/redis-ha/templates/redis-ha-network-policy.yaml b/charts/redis-ha/templates/redis-ha-network-policy.yaml index 8f688ca..3529859 100644 --- a/charts/redis-ha/templates/redis-ha-network-policy.yaml +++ b/charts/redis-ha/templates/redis-ha-network-policy.yaml @@ -31,10 +31,22 @@ spec: release: {{ .Release.Name }} app: {{ template "redis-ha.name" . }} ports: + {{- if ne (int .Values.redis.port) 0 }} - port: {{ .Values.redis.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.port) 0 }} - port: {{ .Values.sentinel.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.redis.tlsPort) 0 }} + - port: {{ .Values.redis.tlsPort }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.tlsPort) 0 }} + - port: {{ .Values.sentinel.tlsPort }} + protocol: TCP + {{- end }} {{- range $rule := .Values.networkPolicy.egressRules }} - to: {{ (tpl (toYaml $rule.selectors) $) | indent 7 }} @@ -48,10 +60,22 @@ spec: release: {{ .Release.Name }} app: {{ template "redis-ha.name" . }} ports: + {{- if ne (int .Values.redis.port) 0 }} - port: {{ .Values.redis.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.port) 0 }} - port: {{ .Values.sentinel.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.redis.tlsPort) 0 }} + - port: {{ .Values.redis.tlsPort }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.tlsPort) 0 }} + - port: {{ .Values.sentinel.tlsPort }} + protocol: TCP + {{- end }} {{- if .Values.haproxy.enabled }} - from: - podSelector: @@ -59,10 +83,22 @@ spec: release: {{ .Release.Name }} app: {{ template "redis-ha.name" . }}-haproxy ports: + {{- if ne (int .Values.redis.port) 0 }} - port: {{ .Values.redis.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.port) 0 }} - port: {{ .Values.sentinel.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.redis.tlsPort) 0 }} + - port: {{ .Values.redis.tlsPort }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.tlsPort) 0 }} + - port: {{ .Values.sentinel.tlsPort }} + protocol: TCP + {{- end }} {{- end }} {{- range $rule := .Values.networkPolicy.ingressRules }} - from: @@ -71,10 +107,22 @@ spec: {{- if $rule.ports }} {{ toYaml $rule.ports | indent 7 }} {{- else }} + {{- if ne (int .Values.redis.port) 0 }} - port: {{ $root.Values.redis.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.port) 0 }} - port: {{ $root.Values.sentinel.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.redis.tlsPort) 0 }} + - port: {{ .Values.redis.tlsPort }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.tlsPort) 0 }} + - port: {{ .Values.sentinel.tlsPort }} + protocol: TCP + {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/redis-ha/templates/redis-haproxy-network-policy.yaml b/charts/redis-ha/templates/redis-haproxy-network-policy.yaml index 2b746ea..f1afb99 100644 --- a/charts/redis-ha/templates/redis-haproxy-network-policy.yaml +++ b/charts/redis-ha/templates/redis-haproxy-network-policy.yaml @@ -31,10 +31,22 @@ spec: release: {{ .Release.Name }} app: {{ template "redis-ha.name" . }} ports: + {{- if ne (int .Values.redis.port) 0 }} - port: {{ .Values.redis.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.port) 0 }} - port: {{ .Values.sentinel.port }} protocol: TCP + {{- end }} + {{- if ne (int .Values.redis.tlsPort) 0 }} + - port: {{ .Values.redis.tlsPort }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.tlsPort) 0 }} + - port: {{ .Values.sentinel.tlsPort }} + protocol: TCP + {{- end }} - to: - namespaceSelector: {} ports: @@ -55,10 +67,22 @@ spec: release: {{ .Release.Name }} app: {{ template "redis-ha.name" . }} ports: - - port: {{ .Values.redis.port }} - protocol: TCP - - port: {{ .Values.sentinel.port }} - protocol: TCP + {{- if ne (int .Values.redis.port) 0 }} + - port: {{ .Values.redis.port }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.port) 0 }} + - port: {{ .Values.sentinel.port }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.redis.tlsPort) 0 }} + - port: {{ .Values.redis.tlsPort }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.tlsPort) 0 }} + - port: {{ .Values.sentinel.tlsPort }} + protocol: TCP + {{- end }} {{- range $rule := .Values.haproxy.networkPolicy.ingressRules }} - from: {{- (tpl (toYaml $rule.selectors) $) | nindent 8 }} @@ -66,9 +90,21 @@ spec: {{- if $rule.ports }} {{- toYaml $rule.ports | nindent 8 }} {{- end }} - - port: {{ $root.Values.redis.port }} - protocol: TCP - - port: {{ $root.Values.sentinel.port }} - protocol: TCP + {{- if ne (int .Values.redis.port) 0 }} + - port: {{ .Values.redis.port }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.port) 0 }} + - port: {{ .Values.sentinel.port }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.redis.tlsPort) 0 }} + - port: {{ .Values.redis.tlsPort }} + protocol: TCP + {{- end }} + {{- if ne (int .Values.sentinel.tlsPort) 0 }} + - port: {{ .Values.sentinel.tlsPort }} + protocol: TCP + {{ end }} {{- end }} {{- end }}