{{- if .Values.clusterRole.enabled -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ printf "%s-%s" (include "authentik-remote-cluster.fullname" .) (include "authauthentik-remote-cluster.namespace" .) | quote }}
  labels:
    {{- include "authentik-remote-cluster.labels" (dict "context" .) | nindent 4 }}
  {{- with .Values.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ printf "%s-%s" (include "authentik-remote-cluster.fullname" .) (include "authauthentik-remote-cluster.namespace" .) | quote }}
subjects:
  - kind: ServiceAccount
    name: {{ template "authentik-remote-cluster.fullname" . }}
    namespace: {{ include "authauthentik-remote-cluster.namespace" . | quote }}
{{- end }}
