{{- if and .Values.rbac.create .Values.multitenancy.enabled (not .Values.multitenancy.privileged) }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  {{- with .Values.rbac.annotations }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
  name: cluster-reconciler-impersonator
  labels:
    app.kubernetes.io/instance: {{ .Release.Namespace | quote }}
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/version: {{ .Chart.AppVersion | quote  }}
    app.kubernetes.io/part-of: flux
    helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
rules:
- apiGroups: [""]
  resources: ["serviceaccounts"]
  verbs: ["impersonate"]
{{- end }}
