networkpolicy.yaml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {{- if .Values.networkPolicy.enabled }}
  2. apiVersion: networking.k8s.io/v1
  3. kind: NetworkPolicy
  4. metadata:
  5. name: {{ template "grafana.fullname" . }}
  6. namespace: {{ template "grafana.namespace" . }}
  7. labels:
  8. {{- include "grafana.labels" . | nindent 4 }}
  9. {{- with .Values.labels }}
  10. {{ toYaml . | nindent 4 }}
  11. {{- end }}
  12. {{- with .Values.annotations }}
  13. annotations:
  14. {{- toYaml . | nindent 4 }}
  15. {{- end }}
  16. spec:
  17. policyTypes:
  18. {{- if .Values.networkPolicy.ingress }}
  19. - Ingress
  20. {{- end }}
  21. {{- if .Values.networkPolicy.egress.enabled }}
  22. - Egress
  23. {{- end }}
  24. podSelector:
  25. matchLabels:
  26. {{- include "grafana.selectorLabels" . | nindent 6 }}
  27. {{- if .Values.networkPolicy.egress.enabled }}
  28. egress:
  29. - ports:
  30. {{ .Values.networkPolicy.egress.ports | toJson }}
  31. {{- end }}
  32. {{- if .Values.networkPolicy.ingress }}
  33. ingress:
  34. - ports:
  35. - port: {{ .Values.service.targetPort }}
  36. {{- if not .Values.networkPolicy.allowExternal }}
  37. from:
  38. - podSelector:
  39. matchLabels:
  40. {{ template "grafana.fullname" . }}-client: "true"
  41. {{- with .Values.networkPolicy.explicitNamespacesSelector }}
  42. - namespaceSelector:
  43. {{- toYaml . | nindent 12 }}
  44. {{- end }}
  45. - podSelector:
  46. matchLabels:
  47. {{- include "grafana.labels" . | nindent 14 }}
  48. role: read
  49. {{- end }}
  50. {{- end }}
  51. {{- end }}