{{- if .Values.rbac.create }}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:userinfo
  labels: {{ include "kyverno.labels" . | nindent 4 }}
    app: kyverno
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:userinfo
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ template "kyverno.namespace" . }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:policies
  labels: {{ include "kyverno.labels" . | nindent 4 }}
    app: kyverno
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:policies
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ template "kyverno.namespace" . }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:view
  labels: {{ include "kyverno.labels" . | nindent 4 }}
    app: kyverno
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:view
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ template "kyverno.namespace" . }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:generate
  labels: {{ include "kyverno.labels" . | nindent 4 }}
    app: kyverno
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:generate
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ template "kyverno.namespace" . }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:events
  labels: {{ include "kyverno.labels" . | nindent 4 }}
    app: kyverno
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:events
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ template "kyverno.namespace" . }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:webhook
  labels: {{ include "kyverno.labels" . | nindent 4 }}
    app: kyverno
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:webhook
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ template "kyverno.namespace" . }}

{{- end }}
