apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: metrics-operator-role
  namespace: {{ .Release.Namespace | quote }}
  {{- $annotations := include "common.annotations" (dict "context" .) }}
  {{- with $annotations }}
  annotations: {{- . -}}
  {{- end }}
  labels:
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
rules:
  - apiGroups:
      - ""
    resources:
      - configmaps
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - get
  - apiGroups:
      - metrics.keptn.sh
    resources:
      - analyses
    verbs:
      - create
      - delete
      - get
      - list
      - patch
      - update
      - watch
  - apiGroups:
      - metrics.keptn.sh
    resources:
      - analyses/finalizers
      - keptnmetrics/finalizers
    verbs:
      - update
  - apiGroups:
      - metrics.keptn.sh
    resources:
      - analyses/status
      - keptnmetrics/status
    verbs:
      - get
      - patch
      - update
  - apiGroups:
      - metrics.keptn.sh
    resources:
      - analysisdefinitions
      - analysisvaluetemplates
      - keptnmetrics
      - keptnmetricsproviders
      - providers
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: metrics-operator-rolebinding
  namespace: {{ .Release.Namespace | quote }}
  {{- with $annotations }}
  annotations: {{- . -}}
  {{- end }}
  labels:
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: 'metrics-operator-role'
subjects:
  - kind: ServiceAccount
    name: 'metrics-operator'
    namespace: '{{ .Release.Namespace }}'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: metrics-operator-rolebinding
  namespace: {{ .Release.Namespace | quote }}
  {{- with $annotations }}
  annotations: {{- . -}}
  {{- end }}
  labels:
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: 'metrics-operator-role'
subjects:
  - kind: ServiceAccount
    name: 'metrics-operator'
    namespace: '{{ .Release.Namespace }}'