networkpolicy.yaml 3.6 KB

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