Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable/redis-ha] Add tls ports to netpol if defined #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/redis-ha/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ keywords:
- redis
- keyvalue
- database
version: 4.32.0
version: 4.33.0
appVersion: 7.2.4
description: This Helm chart provides a highly available Redis implementation with a master/slave configuration and uses Sentinel sidecars for failover management
icon: https://upload.wikimedia.org/wikipedia/en/thumb/6/6b/Redis_Logo.svg/1200px-Redis_Logo.svg.png
Expand Down
24 changes: 24 additions & 0 deletions charts/redis-ha/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,28 @@ Usage:
{{- $adaptedContext = omit $adaptedContext "capabilities" "seLinuxOptions" -}}
{{- end -}}
{{- omit $adaptedContext "enabled" | toYaml -}}
{{- end -}}

{{/*
Defines the redis ports to be used inside network policies
Usage:
{{- include "redis-ports" . -}}
*/}}
{{- define "redis-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 -}}
20 changes: 4 additions & 16 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,7 @@ spec:
release: {{ .Release.Name }}
app: {{ template "redis-ha.name" . }}
ports:
- port: {{ .Values.redis.port }}
protocol: TCP
- port: {{ .Values.sentinel.port }}
protocol: TCP
{{- include "redis-ports" . | nindent 6 }}
{{- range $rule := .Values.networkPolicy.egressRules }}
- to:
{{ (tpl (toYaml $rule.selectors) $) | indent 7 }}
Expand All @@ -48,21 +45,15 @@ spec:
release: {{ .Release.Name }}
app: {{ template "redis-ha.name" . }}
ports:
- port: {{ .Values.redis.port }}
protocol: TCP
- port: {{ .Values.sentinel.port }}
protocol: TCP
{{- include "redis-ports" . | nindent 6 }}
{{- if .Values.haproxy.enabled }}
- from:
- podSelector:
matchLabels:
release: {{ .Release.Name }}
app: {{ template "redis-ha.name" . }}-haproxy
ports:
- port: {{ .Values.redis.port }}
protocol: TCP
- port: {{ .Values.sentinel.port }}
protocol: TCP
{{- include "redis-ports" . | nindent 6 }}
{{- end }}
{{- range $rule := .Values.networkPolicy.ingressRules }}
- from:
Expand All @@ -71,10 +62,7 @@ spec:
{{- if $rule.ports }}
{{ toYaml $rule.ports | indent 7 }}
{{- else }}
- port: {{ $root.Values.redis.port }}
protocol: TCP
- port: {{ $root.Values.sentinel.port }}
protocol: TCP
{{- include "redis-ports" . | nindent 6 }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 3 additions & 12 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,7 @@ spec:
release: {{ .Release.Name }}
app: {{ template "redis-ha.name" . }}
ports:
- port: {{ .Values.redis.port }}
protocol: TCP
- port: {{ .Values.sentinel.port }}
protocol: TCP
{{- include "redis-ports" . | nindent 6 }}
- to:
- namespaceSelector: {}
ports:
Expand All @@ -55,20 +52,14 @@ spec:
release: {{ .Release.Name }}
app: {{ template "redis-ha.name" . }}
ports:
- port: {{ .Values.redis.port }}
protocol: TCP
- port: {{ .Values.sentinel.port }}
protocol: TCP
{{- include "redis-ports" . | nindent 8 }}
{{- 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
{{- include "redis-ports" . | nindent 8 }}
{{- end }}
{{- end }}
Loading