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

{{- if .Values.rbac.create }}
kind: ClusterRole
apiVersion: {{ include "common.capabilities.rbac.apiVersion" . }}
metadata:
  name: {{ include "common.names.fullname.namespace" . }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: minio-operator
    app.kubernetes.io/component: operator
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
rules:
  - apiGroups:
      - "apiextensions.k8s.io"
    resources:
      - customresourcedefinitions
    verbs:
      - get
      - update
  - apiGroups:
      - ""
    resources:
      - persistentvolumeclaims
    verbs:
      - get
      - update
      - list
  - apiGroups:
      - ""
    resources:
      - namespaces
      - nodes
    verbs:
      - create
      - get
      - watch
      - list
  - apiGroups:
      - ""
    resources:
      - pods
      - services
      - events
      - configmaps
    verbs:
      - get
      - watch
      - create
      - list
      - delete
      - deletecollection
      - update
      - patch
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - get
      - watch
      - create
      - update
      - list
      - delete
      - deletecollection
  - apiGroups:
      - ""
    resources:
      - serviceaccounts
    verbs:
      - create
      - delete
      - get
      - list
      - patch
      - update
      - watch
  - apiGroups:
      - rbac.authorization.k8s.io
    resources:
      - roles
      - rolebindings
    verbs:
      - create
      - delete
      - get
      - list
      - patch
      - update
      - watch
  - apiGroups:
      - apps
    resources:
      - statefulsets
      - deployments
      - deployments/finalizers
    verbs:
      - get
      - create
      - list
      - patch
      - watch
      - update
      - delete
  - apiGroups:
      - batch
    resources:
      - jobs
    verbs:
      - get
      - create
      - list
      - patch
      - watch
      - update
      - delete
  - apiGroups:
      - "certificates.k8s.io"
    resources:
      - "certificatesigningrequests"
      - "certificatesigningrequests/approval"
      - "certificatesigningrequests/status"
    verbs:
      - update
      - create
      - get
      - delete
      - list
  - apiGroups:
      - certificates.k8s.io
    resourceNames:
      - kubernetes.io/legacy-unknown
      - kubernetes.io/kube-apiserver-client
      - kubernetes.io/kubelet-serving
      - beta.eks.amazonaws.com/app-serving
    resources:
      - signers
    verbs:
      - approve
      - sign
  - apiGroups:
      - authentication.k8s.io
    resources:
      - tokenreviews
    verbs:
      - create
  - apiGroups:
      - minio.min.io
      - sts.min.io
      - job.min.io
    resources:
      - "*"
    verbs:
      - "*"
  - apiGroups:
      - min.io
    resources:
      - "*"
    verbs:
      - "*"
  - apiGroups:
      - monitoring.coreos.com
    resources:
      - prometheuses
      - prometheusagents
    verbs:
      - get
      - update
      - list
  - apiGroups:
      - "coordination.k8s.io"
    resources:
      - leases
    verbs:
      - get
      - update
      - create
  - apiGroups:
      - policy
    resources:
      - poddisruptionbudgets
    verbs:
      - create
      - delete
      - get
      - list
      - patch
      - update
      - deletecollection
  {{- if .Values.rbac.rules }}
  {{- include "common.tplvalues.render" ( dict "value" .Values.rbac.rules "context" $ ) | nindent 2 }}
  {{- end }}
{{- end }}
