{{- if .Values.networkPolicy.enabled }}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: {{ template "prometheus-blackbox-exporter.fullname" . }}
spec:
  podSelector:
    matchLabels:
      app.kubernetes.io/instance: {{ $.Release.Name }}
      app.kubernetes.io/name: {{ include "prometheus-blackbox-exporter.name" $ }}
  ingress:
{{- if .Values.networkPolicy.allowMonitoringNamespace }}
  - from:
    - namespaceSelector:
        matchLabels:
          name: monitoring
    ports:
    - port: {{ .Values.service.port }}
      protocol: TCP
{{- else }}
  - {}
{{- end }}
  policyTypes:
  - Ingress
{{- end }}

