{{- if and .Values.kubeStateMetrics.enabled .Values.rbac.create -}}
{{- if .Values.podSecurityPolicy.enabled }}
apiVersion: {{ template "rbac.apiVersion" . }}
kind: ClusterRoleBinding
metadata:
  labels:
    {{- include "prometheus.kubeStateMetrics.labels" . | nindent 4 }}
  name: psp-{{ template "prometheus.kubeStateMetrics.fullname" . }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: psp-{{ template "prometheus.kubeStateMetrics.fullname" . }}
subjects:
  - kind: ServiceAccount
    name: {{ template "prometheus.serviceAccountName.kubeStateMetrics" . }}
    namespace: {{ .Release.Namespace }}
{{- end }}
{{- end }}
