{{- if and .Values.pushgateway.enabled .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  labels:
    {{- include "prometheus.pushgateway.labels" . | nindent 4 }}
  name: {{ template "prometheus.pushgateway.fullname" . }}
rules:
{{- if .Values.podSecurityPolicy.enabled }}
  - apiGroups:
    - extensions
    resources:
    - podsecuritypolicies
    verbs:
    - use
    resourceNames:
    - {{ template "prometheus.pushgateway.fullname" . }}
{{- else }}
  []
{{- end }}
{{- end }}
