{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if .Values.clusterOperator.rbac.create }}
apiVersion: {{ include "common.capabilities.rbac.apiVersion" . }}
kind: ClusterRole
metadata:
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: rabbitmq-operator
    app.kubernetes.io/part-of: rabbitmq
  name: {{ template "common.names.fullname.namespace" . }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
rules:
  {{- if .Values.clusterOperator.rbac.clusterRole.customRules }}
  {{- range .Values.clusterOperator.rbac.clusterRole.customRules }}
  - apiGroups: {{ .apiGroups | toYaml | nindent 6 }}
    resources: {{ .resources | toYaml | nindent 6 }}
    verbs: {{ .verbs | toYaml | nindent 6 }}
  {{- end }}
  {{- else }}
  {{- if .Values.clusterOperator.rbac.clusterRole.extraRules }}
  {{- range .Values.clusterOperator.rbac.clusterRole.extraRules }}
  - apiGroups: {{ .apiGroups | toYaml | nindent 6 }}
    resources: {{ .resources | toYaml | nindent 6 }}
    verbs: {{ .verbs | toYaml | nindent 6 }}
  {{- end }}
  {{- end }}
  - apiGroups:
      - ""
    resources:
      - configmaps
    verbs:
      - create
      - get
      - list
      - update
      - watch
  - apiGroups:
      - ""
    resources:
      - endpoints
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - events
    verbs:
      - create
      - get
      - patch
  - apiGroups:
      - ""
    resources:
      - persistentvolumeclaims
    verbs:
      - create
      - get
      - list
      - update
      - watch
  - apiGroups:
      - ""
    resources:
      - pods
    verbs:
      - get
      - list
      - update
      - watch
  - apiGroups:
      - ""
    resources:
      - pods/exec
    verbs:
      - create
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - create
      - get
      - list
      - update
      - watch
  - apiGroups:
      - ""
    resources:
      - serviceaccounts
    verbs:
      - create
      - get
      - list
      - update
      - watch
  - apiGroups:
      - ""
    resources:
      - services
    verbs:
      - create
      - get
      - list
      - update
      - watch
  - apiGroups:
      - apps
    resources:
      - statefulsets
    verbs:
      - create
      - delete
      - get
      - list
      - update
      - watch
  - apiGroups:
      - rabbitmq.com
    resources:
      - rabbitmqclusters
    verbs:
      - create
      - get
      - list
      - update
      - watch
  - apiGroups:
      - rabbitmq.com
    resources:
      - rabbitmqclusters/finalizers
    verbs:
      - update
  - apiGroups:
      - rabbitmq.com
    resources:
      - rabbitmqclusters/status
    verbs:
      - get
      - update
  - apiGroups:
      - rbac.authorization.k8s.io
    resources:
      - rolebindings
    verbs:
      - create
      - get
      - list
      - update
      - watch
  - apiGroups:
      - rbac.authorization.k8s.io
    resources:
      - roles
    verbs:
      - create
      - get
      - list
      - update
      - watch
  {{- end }}
{{- end }}
