{{- if and ( .Values.reloader.netpol.enabled ) }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  annotations:
{{ include "reloader-helm3.annotations" . | indent 4 }}
  labels:
{{ include "reloader-labels.chart" . | indent 4 }}
{{- if .Values.reloader.matchLabels }}
{{ toYaml .Values.reloader.matchLabels | indent 4 }}
{{- end }}
  name: {{ template "reloader-fullname" . }}
  namespace: {{ .Values.namespace | default .Release.Namespace }}
spec:
  podSelector:
    matchLabels:
      app: {{ template "reloader-fullname" . }}
      release: {{ .Release.Name | quote }}
{{- if .Values.reloader.matchLabels }}
{{ toYaml .Values.reloader.matchLabels | indent 6 }}
{{- end }}
  policyTypes:
  - Ingress
  - Egress
  ingress:
    - ports:
        - port: http
      {{- with .Values.reloader.netpol.from}}
      from:
        {{- toYaml .| nindent 8 }}
      {{- end }}
  egress:
    - ports:
        - port: 443
      {{- with .Values.reloader.netpol.to}}
      to:
        {{- toYaml .| nindent 8 }}
      {{- end }}
{{- end }}
