{{- if .Values.networkPolicy.enabled }}
kind: NetworkPolicy
apiVersion: {{ template "networkPolicy.apiVersion" . }}
metadata:
  name: {{ template "nats.fullname" . }}
  labels:
    app: "{{ template "nats.name" . }}"
    chart: "{{ template "nats.chart" . }}"
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
spec:
  podSelector:
    matchLabels:
      app: "{{ template "nats.name" . }}"
      release: {{ .Release.Name | quote }}
  ingress:
    # Allow inbound connections
    - ports:
      - port: {{ .Values.client.service.port }}
      {{- if not .Values.networkPolicy.allowExternal }}
      from:
        - podSelector:
            matchLabels:
              {{ template "nats.fullname" . }}-client: "true"
      {{- end }}
    - ports:
      - port: {{ .Values.cluster.service.port }}
    - ports:
      - port: {{ .Values.monitoring.service.port }}
{{- end }}
