networkpolicy.yaml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. {{- /*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{- if .Values.primary.networkPolicy.enabled }}
  6. kind: NetworkPolicy
  7. apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
  8. metadata:
  9. name: {{ include "postgresql.v1.readReplica.fullname" . }}
  10. namespace: {{ include "common.names.namespace" . | quote }}
  11. labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  12. app.kubernetes.io/component: read
  13. {{- if .Values.commonAnnotations }}
  14. annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  15. {{- end }}
  16. spec:
  17. {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.primary.podLabels .Values.commonLabels ) "context" . ) }}
  18. podSelector:
  19. matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }}
  20. app.kubernetes.io/component: read
  21. policyTypes:
  22. - Ingress
  23. - Egress
  24. {{- if .Values.primary.networkPolicy.allowExternalEgress }}
  25. egress:
  26. - {}
  27. {{- else }}
  28. egress:
  29. # Allow dns resolution
  30. - ports:
  31. - port: 53
  32. protocol: UDP
  33. - port: 53
  34. protocol: TCP
  35. # Allow outbound connections to primary
  36. - ports:
  37. - port: {{ include "postgresql.v1.service.port" . }}
  38. - port: {{ .Values.containerPorts.postgresql }}
  39. to:
  40. - podSelector:
  41. matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }}
  42. app.kubernetes.io/component: primary
  43. {{- if .Values.primary.networkPolicy.extraEgress }}
  44. {{- include "common.tplvalues.render" ( dict "value" .Values.primary.networkPolicy.extraEgress "context" $ ) | nindent 4 }}
  45. {{- end }}
  46. {{- end }}
  47. ingress:
  48. - ports:
  49. - port: {{ .Values.containerPorts.postgresql }}
  50. {{- if .Values.metrics.enabled }}
  51. - port: {{ .Values.metrics.containerPorts.metrics }}
  52. {{- end }}
  53. {{- if not .Values.primary.networkPolicy.allowExternal }}
  54. from:
  55. - podSelector:
  56. matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 14 }}
  57. - podSelector:
  58. matchLabels:
  59. {{ template "postgresql.v1.primary.fullname" . }}-client: "true"
  60. {{- if .Values.primary.networkPolicy.ingressNSMatchLabels }}
  61. - namespaceSelector:
  62. matchLabels:
  63. {{- range $key, $value := .Values.primary.networkPolicy.ingressNSMatchLabels }}
  64. {{ $key | quote }}: {{ $value | quote }}
  65. {{- end }}
  66. {{- if .Values.primary.networkPolicy.ingressNSPodMatchLabels }}
  67. podSelector:
  68. matchLabels:
  69. {{- range $key, $value := .Values.primary.networkPolicy.ingressNSPodMatchLabels }}
  70. {{ $key | quote }}: {{ $value | quote }}
  71. {{- end }}
  72. {{- end }}
  73. {{- end }}
  74. {{- end }}
  75. {{- if .Values.primary.networkPolicy.extraIngress }}
  76. {{- include "common.tplvalues.render" ( dict "value" .Values.primary.networkPolicy.extraIngress "context" $ ) | nindent 4 }}
  77. {{- end }}
  78. {{- end }}