{{- if .Values.rbac.create -}}
# Specifies either
#   ClusterRoleBinding between ClusterRole and ServiceAccount.
# or
#   RoleBinding between Role and ServiceAccount.
# ClusterRoleBinding is namespace-less and must have unique name
# RoleBinding is namespace-bound
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ include "altinity-clickhouse-operator.fullname" . }}
  #namespace: kube-system
  labels: {{ include "altinity-clickhouse-operator.labels" . | nindent 4 }}
  namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ include "altinity-clickhouse-operator.fullname" . }}
subjects:
  - kind: ServiceAccount
    name: {{ include "altinity-clickhouse-operator.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
{{- end }}
