Oleksandr Kozachenko | b009349 | 2023-09-06 21:43:47 +0200 | [diff] [blame] | 1 | {{- /* |
| 2 | Copyright VMware, Inc. |
| 3 | SPDX-License-Identifier: APACHE-2.0 |
| 4 | */}} |
| 5 | |
| 6 | {{- if .Values.networkPolicy.enabled }} |
| 7 | kind: NetworkPolicy |
| 8 | apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }} |
| 9 | metadata: |
| 10 | name: {{ template "common.names.fullname" . }} |
| 11 | namespace: {{ include "common.names.namespace" . | quote }} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 12 | labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} |
Oleksandr Kozachenko | b009349 | 2023-09-06 21:43:47 +0200 | [diff] [blame] | 13 | app.kubernetes.io/component: keycloak |
Oleksandr Kozachenko | b009349 | 2023-09-06 21:43:47 +0200 | [diff] [blame] | 14 | {{- if .Values.commonAnnotations }} |
| 15 | annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} |
| 16 | {{- end }} |
| 17 | spec: |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 18 | {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.podLabels .Values.commonLabels ) "context" . ) }} |
Oleksandr Kozachenko | b009349 | 2023-09-06 21:43:47 +0200 | [diff] [blame] | 19 | podSelector: |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 20 | 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 Kozachenko | b009349 | 2023-09-06 21:43:47 +0200 | [diff] [blame] | 64 | 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 Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 74 | matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }} |
| 75 | - podSelector: |
Oleksandr Kozachenko | b009349 | 2023-09-06 21:43:47 +0200 | [diff] [blame] | 76 | matchLabels: |
| 77 | {{ template "common.names.fullname" . }}-client: "true" |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 78 | {{- 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 Kozachenko | b009349 | 2023-09-06 21:43:47 +0200 | [diff] [blame] | 91 | {{- end }} |
| 92 | {{- end }} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 93 | {{- $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 Kozachenko | b009349 | 2023-09-06 21:43:47 +0200 | [diff] [blame] | 97 | {{- end }} |