{{- if and .Values.starrocksOperator.enabled .Values.global.rbac.create }}
{{- if .Values.starrocksOperator.watchNamespace | not }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ template "operator.name" . }}-operator
  labels:
    app: {{ template "operator.name" . }}-operator
rules:
- apiGroups:
  - apps
  resources:
  - deployments
  - statefulsets
  verbs:
  - '*'
- apiGroups:
  - autoscaling
  resources:
  - horizontalpodautoscalers
  verbs:
  - '*'
- apiGroups:
  - batch
  resources:
  - cronjobs
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - configmaps
  - serviceaccounts
  - services
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - endpoints
  - pods
  - secrets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - starrocks.com
  resources:
  - starrocksclusters
  - starrockswarehouses
  verbs:
  - '*'
# when deploying to OpenShift, the following permission is also necessary
- apiGroups:
  - starrocks.com
  resources:
  - starrocksclusters/finalizers
  - starrockswarehouses/finalizers
  verbs:
  - update
- apiGroups:
  - starrocks.com
  resources:
  - starrocksclusters/status
  - starrockswarehouses/status
  verbs:
  - get
  - patch
  - update

{{- end }}
{{- end }}
