{{- if .Values.admissionController.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ template "kyverno.admission-controller.roleName" . }}
  namespace: {{ template "kyverno.namespace" . }}
  labels:
    {{- include "kyverno.admission-controller.labels" . | nindent 4 }}
rules:
  - apiGroups:
      - ''
    resources:
      - secrets
    verbs:
      - get
      - list
      - watch
      - create
      - update
  - apiGroups:
      - ''
    resources:
      - configmaps
    verbs:
      - get
      - list
      - watch
    resourceNames:
      - {{ include "kyverno.config.configMapName" . }}
      - {{ include "kyverno.config.metricsConfigMapName" . }}
  - apiGroups:
      - coordination.k8s.io
    resources:
      - leases
    verbs:
      - create
      - delete
      - get
      - patch
      - update
  # Allow update of Kyverno deployment annotations
  - apiGroups:
      - apps
    resources:
      - deployments
      {{- if .Values.webhooksCleanup.enabled }}
      - deployments/scale
      {{- end }}
    verbs:
      - get
      - list
      - watch
      {{- if .Values.webhooksCleanup.enabled }}
      - patch
      - update
      {{- end }}
{{- end -}}
