{{- if  and .Values.rbac.create  (not .Values.watchNamespace) -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ template "vm-operator.fullname" . }}
  labels:
{{ include "vm-operator.labels" . | indent 4 }}
rules:
- apiGroups:
  - ""
  resources:
  - configmaps
  - configmaps/finalizers
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - endpoints
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - namespaces
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - persistentvolumeclaims
  - persistentvolumeclaims/finalizers
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - pods
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - secrets
  - secrets/finalizers
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - services
  verbs:
  - '*'
- apiGroups:
  - ""
  resources:
  - services/finalizers
  verbs:
  - '*'
- apiGroups:
  - apps
  resources:
  - deployments
  - deployments/finalizers
  verbs:
  - '*'
- apiGroups:
  - apps
  resources:
  - replicasets
  verbs:
  - '*'
- apiGroups:
  - apps
  resources:
  - statefulsets
  - statefulsets/finalizers
  - statefulsets/status
  verbs:
  - '*'
- apiGroups:
  - monitoring.coreos.com
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmagents
  - vmagents/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmagents/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmalertmanagers
  - vmalertmanagers/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmalertmanagers/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmalertmanagerconfigs
  - vmalertmanagerconfigs/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmalertmanagerconfigss/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmalerts
  - vmalerts/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmalerts/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmclusters
  - vmclusters/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmclusters/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmpodscrapes
  - vmprobscrapes/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmpodscrapes/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmrules
  - vmrules/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmrules/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmservicescrapes
  - vmservicescrapes/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmservicescrapes/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmprobes
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmprobes/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmsingles
  - vmsingles/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - operator.victoriametrics.com
  resources:
  - vmsingles/status
  verbs:
  - get
  - patch
  - update
- apiGroups:
    - ""
  resources:
    - nodes
    - nodes/proxy
    - services
    - endpoints
    - pods
    - endpointslices
    - configmaps
    - nodes/metrics
    - namespaces
  verbs:
    - get
    - list
    - watch
- apiGroups:
    - "extensions"
    - "networking.k8s.io"
  resources:
    - ingresses
  verbs:
    - get
    - list
    - watch
- nonResourceURLs:
    - "/metrics"
    - "/metrics/resources"
  verbs:
    - get
    - watch
    - list
- apiGroups:
    - "rbac.authorization.k8s.io"
  resources:
    - clusterrolebindings
    - clusterrolebindings/finalizers
    - clusterroles
    - clusterroles/finalizers
    - roles
    - rolebindings
  verbs:
    - get
    - list
    - create
    - patch
    - update
    - watch
    - delete
- apiGroups:
    - "policy"
  resources:
    - podsecuritypolicies
    - podsecuritypolicies/finalizers
  verbs:
    - get
    - list
    - create
    - patch
    - update
    - use
    - watch
    - delete
- apiGroups:
    - ""
  resources:
    - serviceaccounts
    - serviceaccounts/finalizers
  verbs:
    - get
    - list
    - create
    - watch
    - update
    - delete
- apiGroups:
    - operator.victoriametrics.com
  resources:
    - vmnodescrapes
    - vmnodescrapes/finalizers
  verbs:
    - create
    - delete
    - get
    - list
    - patch
    - update
    - watch
- apiGroups:
    - operator.victoriametrics.com
  resources:
    - vmnodescrapes/status
  verbs:
    - get
    - patch
    - update
- apiGroups:
    - operator.victoriametrics.com
  resources:
    - vmstaticscrapes
    - vmstaticscrapes/finalizers
  verbs:
    - create
    - delete
    - get
    - list
    - patch
    - update
    - watch
- apiGroups:
    - operator.victoriametrics.com
  resources:
    - vmstaticscrapes/status
  verbs:
    - get
    - patch
    - update
- apiGroups:
    - operator.victoriametrics.com
  resources:
  - vmauths
  - vmauths/finalizers
  - vmusers
  - vmusers/finalizers
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
    - operator.victoriametrics.com
  resources:
    - vmusers/status
    - vmauths/status
  verbs:
    - get
    - patch
    - update
- apiGroups:
    - storage.k8s.io
  resources:
    - storageclasses
  verbs:
    - list
    - get
    - watch
- apiGroups:
    - policy
  resources:
    - poddisruptionbudgets
    - poddisruptionbudgets/finalizers
  verbs:
    - '*'
- apiGroups:
    - route.openshift.io
    - image.openshift.io
  resources:
    - routers/metrics
    - registry/metrics
  verbs:
    - get
- apiGroups:
    - autoscaling
  verbs:
    - list
    - get
    - delete
    - create
    - update
    - watch
  resources:
    - horizontalpodautoscalers
- apiGroups:
    - networking.k8s.io
    - extensions
  resources:
  - ingresses
  - ingresses/finalizers
  verbs:
  - create
  - delete
  - get
  - patch
  - update
  - watch
- apiGroups:
    - apiextensions.k8s.io
  resources:
    - customresourcedefinitions
  verbs:
    - get
    - list
{{- end -}}
