Skip to content

Commit

Permalink
feat(redis-ha): Add tls ports to netpol if defined
Browse files Browse the repository at this point in the history
Signed-off-by: OpenGuidou <[email protected]>
  • Loading branch information
OpenGuidou committed Jan 2, 2025
1 parent 697cba5 commit 6515a2e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 8 deletions.
48 changes: 48 additions & 0 deletions charts/redis-ha/templates/redis-ha-network-policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -48,21 +60,45 @@ 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:
matchLabels:
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:
Expand All @@ -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 }}
52 changes: 44 additions & 8 deletions charts/redis-ha/templates/redis-haproxy-network-policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -55,20 +67,44 @@ 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 }}
ports:
{{- 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 }}

0 comments on commit 6515a2e

Please sign in to comment.