{{- if and .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  {{- with .Values.rbac.annotations }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
  name: crd-controller
  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 "+" "_" }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: crd-controller
subjects:
  - kind: ServiceAccount
    name: kustomize-controller
    namespace: {{ .Release.Namespace }}
  - kind: ServiceAccount
    name: helm-controller
    namespace: {{ .Release.Namespace }}
  - kind: ServiceAccount
    name: source-controller
    namespace: {{ .Release.Namespace }}
  - kind: ServiceAccount
    name: notification-controller
    namespace: {{ .Release.Namespace }}
  - kind: ServiceAccount
    name: image-reflector-controller
    namespace: {{ .Release.Namespace }}
  - kind: ServiceAccount
    name: image-automation-controller
    namespace: {{ .Release.Namespace }}
{{- end }}
