{{- if .Values.pspEnabled }}
{{ if $.Capabilities.APIVersions.Has "policy/v1/PodSecurityPolicy" -}}
apiVersion: policy/v1
{{- else -}}
apiVersion: policy/v1beta1
{{- end }}
kind: PodSecurityPolicy
metadata:
  name: {{ template "prometheus-blackbox-exporter.fullname" . }}-psp
  namespace: {{ template "prometheus-blackbox-exporter.namespace" . }}
  labels:
    {{- include "prometheus-blackbox-exporter.labels" . | nindent 4 }}
spec:
  # Prevents running in privileged mode
  privileged: false
  # Required to prevent escalations to root.
  allowPrivilegeEscalation: false
  volumes:
    - configMap
    - secret
  hostNetwork: false
  hostIPC: false
  hostPID: false
  runAsUser:
    rule: RunAsAny
  seLinux:
    rule: RunAsAny
  supplementalGroups:
    rule: 'MustRunAs'
    ranges:
      # Forbid adding the root group.
      - min: 1
        max: 65535
  fsGroup:
    rule: 'MustRunAs'
    ranges:
      # Forbid adding the root group.
      - min: 1
        max: 65535
  readOnlyRootFilesystem: {{ .Values.readOnlyRootFilesystem }}
  {{- if .Values.allowIcmp }}
  allowedCapabilities: 
  - NET_RAW
  {{- end }}
{{- end }}
