{{- if .Values.backend.networkPolicy.enabled }} kind: NetworkPolicy apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }} metadata: name: {{ template "shuffle.backend.name" . }} namespace: {{ include "common.names.namespace" . | quote }} labels: {{- include "shuffle.backend.labels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} {{- if .Values.commonAnnotations }} annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} {{- end }} spec: {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.backend.podLabels .Values.commonLabels ) "context" . ) }} podSelector: matchLabels: {{- include "shuffle.backend.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }} policyTypes: - Ingress - Egress egress: {{- if .Values.backend.networkPolicy.allowExternalEgress }} - {} {{- else }} # Allow DNS resolution with an in-cluster DNS server - ports: - port: 53 protocol: UDP - port: 53 protocol: TCP to: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system {{- if .Values.backend.networkPolicy.extraEgress }} {{- include "common.tplvalues.render" ( dict "value" .Values.backend.networkPolicy.extraEgress "context" $ ) | nindent 4 }} {{- end }} {{- end }} ingress: - ports: - port: {{ .Values.backend.containerPorts.http }} protocol: TCP {{- if not .Values.backend.networkPolicy.allowExternal }} from: # Allow traffic from orborus - namespaceSelector: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: matchLabels: {{ include "shuffle.orborus.matchLabels" . | nindent 14 }} # Allow traffic from workers - namespaceSelector: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: matchLabels: {{ include "shuffle.worker.matchLabels" . | nindent 14 }} # Allow traffic from apps - namespaceSelector: matchLabels: kubernetes.io/metadata.name: {{ .Release.Namespace }} podSelector: matchLabels: {{ include "shuffle.app.matchLabels" . | nindent 14 }} {{- end }} {{- if .Values.backend.networkPolicy.extraIngress }} {{- include "common.tplvalues.render" ( dict "value" .Values.backend.networkPolicy.extraIngress "context" $ ) | nindent 4 }} {{- end }} {{- end }}