{{- if .Values.networkPolicy.enabled }}
kind: NetworkPolicy
apiVersion: {{ template "influxdb.networkPolicy.apiVersion" . }}
metadata:
  name: {{ include "influxdb.fullname" . }}
  labels: {{- include "influxdb.labels" . | nindent 4 }}
spec:
  podSelector:
    matchLabels:  {{ include "influxdb.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: influxdb
  policyTypes:
    - Ingress
  ingress:
    # Allow inbound connections
    - ports:
        - port: {{ .Values.influxdb.containerPorts.http }}
          protocol: TCP
        - port: {{ .Values.influxdb.containerPorts.rpc }}
          protocol: TCP
      {{- if not .Values.networkPolicy.allowExternal }}
      from:
        - podSelector:
            matchLabels:
              {{ template "influxdb.fullname" . }}-client: "true"
        {{- if eq .Values.architecture "high-availability" }}
        - podSelector:
            matchLabels: {{- include "influxdb.matchLabels" . | nindent 14 }}
              app.kubernetes.io/component: relay
        {{- end }}
      {{- end }}
{{- end }}
