blob: 348b744f43562108ac7b47e1158db4ddd89e717a [file] [log] [blame]
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +02001{{- /*
2Copyright VMware, Inc.
3SPDX-License-Identifier: APACHE-2.0
4*/}}
5
6{{- if .Values.networkPolicy.enabled }}
7kind: NetworkPolicy
8apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
9metadata:
10 name: {{ template "common.names.fullname" . }}
11 namespace: {{ include "common.names.namespace" . | quote }}
Mohammed Naser65cda132024-05-02 14:34:08 -040012 labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020013 app.kubernetes.io/component: keycloak
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020014 {{- if .Values.commonAnnotations }}
15 annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
16 {{- end }}
17spec:
Mohammed Naser65cda132024-05-02 14:34:08 -040018 {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.podLabels .Values.commonLabels ) "context" . ) }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020019 podSelector:
Mohammed Naser65cda132024-05-02 14:34:08 -040020 matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }}
21 app.kubernetes.io/component: keycloak
22 policyTypes:
23 - Ingress
24 - Egress
25 {{- if .Values.networkPolicy.allowExternalEgress }}
26 egress:
27 - {}
28 {{- else }}
29 egress:
30 - ports:
31 # Allow dns resolution
32 - port: 53
33 protocol: UDP
34 - port: 53
35 protocol: TCP
36 {{- range $port := .Values.networkPolicy.kubeAPIServerPorts }}
37 - port: {{ $port }}
38 {{- end }}
39 # Allow connection to PostgreSQL
40 - ports:
41 - port: {{ include "keycloak.databasePort" . | trimAll "\"" | int }}
42 {{- if .Values.postgresql.enabled }}
43 to:
44 - podSelector:
45 matchLabels:
46 app.kubernetes.io/name: postgresql
47 app.kubernetes.io/instance: {{ .Release.Name }}
48 {{- end }}
49 # Allow connection to other keycloak nodes
50 - ports:
51 - port: {{ .Values.containerPorts.infinispan }}
52 - port: {{ .Values.containerPorts.http }}
53 {{- if .Values.tls.enabled }}
54 - port: {{ .Values.containerPorts.https }}
55 {{- end }}
56 to:
57 - podSelector:
58 matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }}
59 app.kubernetes.io/component: keycloak
60 {{- if .Values.networkPolicy.extraEgress }}
61 {{- include "common.tplvalues.render" ( dict "value" .Values.networkPolicy.extraEgress "context" $ ) | nindent 4 }}
62 {{- end }}
63 {{- end }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020064 ingress:
65 - ports:
66 - port: {{ .Values.containerPorts.infinispan }}
67 - port: {{ .Values.containerPorts.http }}
68 {{- if .Values.tls.enabled }}
69 - port: {{ .Values.containerPorts.https }}
70 {{- end }}
71 {{- if not .Values.networkPolicy.allowExternal }}
72 from:
73 - podSelector:
Mohammed Naser65cda132024-05-02 14:34:08 -040074 matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }}
75 - podSelector:
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020076 matchLabels:
77 {{ template "common.names.fullname" . }}-client: "true"
Mohammed Naser65cda132024-05-02 14:34:08 -040078 {{- if .Values.networkPolicy.ingressNSMatchLabels }}
79 - namespaceSelector:
80 matchLabels:
81 {{- range $key, $value := .Values.networkPolicy.ingressNSMatchLabels }}
82 {{ $key | quote }}: {{ $value | quote }}
83 {{- end }}
84 {{- if .Values.networkPolicy.ingressNSPodMatchLabels }}
85 podSelector:
86 matchLabels:
87 {{- range $key, $value := .Values.networkPolicy.ingressNSPodMatchLabels }}
88 {{ $key | quote }}: {{ $value | quote }}
89 {{- end }}
90 {{- end }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020091 {{- end }}
92 {{- end }}
Mohammed Naser65cda132024-05-02 14:34:08 -040093 {{- $extraIngress := coalesce .Values.networkPolicy.additionalRules .Values.networkPolicy.extraIngress }}
94 {{- if $extraIngress }}
95 {{- include "common.tplvalues.render" ( dict "value" $extraIngress "context" $ ) | nindent 4 }}
96 {{- end }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020097{{- end }}