{{- if .Values.rbac.create }}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:webhook
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:webhook
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:userinfo
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:userinfo
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:customresources
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:customresources
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:policycontroller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:policycontroller
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
---  
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ template "kyverno.fullname" . }}:generatecontroller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kyverno.fullname" . }}:generatecontroller
subjects:
- kind: ServiceAccount
  name: {{ template "kyverno.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
{{- end }}
