Andreas Geissler | cde4a78 | 2024-02-28 16:08:06 +0100 | [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: {{ include "mongodb.fullname" . }} |
| 11 | namespace: {{ include "common.names.namespace" . | quote }} |
| 12 | {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.labels .Values.commonLabels ) "context" . ) }} |
| 13 | labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }} |
| 14 | app.kubernetes.io/component: mongodb |
| 15 | {{- if or .Values.annotations .Values.commonAnnotation }} |
| 16 | {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.annotations .Values.commonAnnotations ) "context" . ) }} |
| 17 | annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }} |
| 18 | {{- end }} |
| 19 | spec: |
| 20 | {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.podLabels .Values.commonLabels ) "context" . ) }} |
| 21 | podSelector: |
| 22 | matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }} |
| 23 | app.kubernetes.io/component: mongodb |
| 24 | policyTypes: |
| 25 | - Ingress |
| 26 | - Egress |
| 27 | {{- if .Values.networkPolicy.allowExternalEgress }} |
| 28 | egress: |
| 29 | - {} |
| 30 | {{- else }} |
| 31 | egress: |
| 32 | # Allow dns resolution |
| 33 | - ports: |
| 34 | - port: 53 |
| 35 | protocol: UDP |
| 36 | - port: 53 |
| 37 | protocol: TCP |
| 38 | # Allow connection to other cluster pods |
| 39 | - ports: |
| 40 | - port: {{ .Values.containerPorts.mongodb }} |
| 41 | to: |
| 42 | - podSelector: |
| 43 | matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }} |
| 44 | {{- if .Values.networkPolicy.extraEgress }} |
| 45 | {{- include "common.tplvalues.render" ( dict "value" .Values.rts.networkPolicy.extraEgress "context" $ ) | nindent 4 }} |
| 46 | {{- end }} |
| 47 | {{- end }} |
| 48 | ingress: |
| 49 | - ports: |
| 50 | - port: {{ .Values.containerPorts.mongodb }} |
| 51 | {{- if .Values.metrics.enabled }} |
| 52 | - port: {{ .Values.metrics.containerPort }} |
| 53 | {{- end }} |
| 54 | {{- if not .Values.networkPolicy.allowExternal }} |
| 55 | from: |
| 56 | - podSelector: |
| 57 | matchLabels: |
| 58 | {{ template "common.names.fullname" . }}-client: "true" |
| 59 | - podSelector: |
| 60 | matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }} |
| 61 | app.kubernetes.io/component: mongodb |
| 62 | {{- $ingressNSMatchLabels := coalesce .Values.networkPolicy.ingressNSMatchLabels .Values.networkPolicy.namespaceSelector }} |
| 63 | {{- if $ingressNSMatchLabels }} |
| 64 | - namespaceSelector: |
| 65 | matchLabels: |
| 66 | {{- range $key, $value := $ingressNSMatchLabels }} |
| 67 | {{ $key | quote }}: {{ $value | quote }} |
| 68 | {{- end }} |
| 69 | {{- $ingressNSPodMatchLabels := coalesce .Values.networkPolicy.ingressNSPodMatchLabels .Values.networkPolicy.podSelector }} |
| 70 | {{- if $ingressNSPodMatchLabels }} |
| 71 | podSelector: |
| 72 | matchLabels: |
| 73 | {{- range $key, $value := $ingressNSPodMatchLabels }} |
| 74 | {{ $key | quote }}: {{ $value | quote }} |
| 75 | {{- end }} |
| 76 | {{- end }} |
| 77 | {{- end }} |
| 78 | {{- end }} |
| 79 | {{- $extraIngress := coalesce .Values.networkPolicy.extraIngress .Values.networkPolicy.customRules }} |
| 80 | {{- if $extraIngress }} |
| 81 | {{- include "common.tplvalues.render" ( dict "value" $extraIngress "context" $ ) | nindent 4 }} |
| 82 | {{- end }} |
| 83 | {{- end }} |