{{- if and .Values.rbac.create .Values.collector.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: collector
    kubernetes.io/bootstrapping: rbac-defaults
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
  name: {{ template "common.names.fullname" . }}-collector
rules:
  - apiGroups:
      - ""
    resources:
      - events
      - namespaces
      - nodes
      - nodes/stats
      - pods
      - services
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - configmaps
    verbs:
      - get
      - update
      - create
      - list
      - watch

{{- if .Values.collector.kubernetesState }}
  - apiGroups:
      - apps
    resources:
      - daemonsets
      - deployments
      - statefulsets
      - replicasets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - batch
    resources:
      - jobs
      - cronjobs
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - autoscaling
    resources:
      - horizontalpodautoscalers
    verbs:
      - get
      - list
      - watch
{{- end }}
  - nonResourceURLs: ["/metrics"]
    verbs:
      - get
{{- end }}
