{{- if and .Values.rbac.create .Values.multitenancy.enabled (not .Values.multitenancy.privileged) }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  {{- with .Values.rbac.annotations }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
  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 "+" "_" }}
  name: cluster-reconciler-impersonator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-reconciler-impersonator
subjects:
- kind: ServiceAccount
  name: kustomize-controller
  namespace: {{ .Release.Namespace }}
- kind: ServiceAccount
  name: helm-controller
  namespace: {{ .Release.Namespace }}
{{- end }}
