{{- if .Values.rbac.create }}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  labels:
{{ include "kanister-operator.helmLabels" . | indent 4 }}
  name: {{ template "kanister-operator.fullname" . }}-cluster-role
rules:
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
- apiGroups:
  - apiextensions.k8s.io
  resources:
  - customresourcedefinitions
  verbs:
  - '*'
- apiGroups:
  - cr.kanister.io
  resources:
  - '*'
  verbs:
  - '*'
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  labels:
{{ include "kanister-operator.helmLabels" . | indent 4 }}
  name: {{ template "kanister-operator.fullname" . }}-edit-role
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: edit
subjects:
- kind: ServiceAccount
  name: {{ template "kanister-operator.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  labels:
{{ include "kanister-operator.helmLabels" . | indent 4 }}
  name: {{ template "kanister-operator.fullname" . }}-cr-role
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "kanister-operator.fullname" . }}-cluster-role
subjects:
- kind: ServiceAccount
  name: {{ template "kanister-operator.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
{{- end }}
