{{- if or .Values.metrics.serviceMonitor.enabled .Values.metrics.podMonitor.enabled }}
{{- $fullName := include "minio.fullname" . -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ $fullName }}-update-prometheus-secret
  labels:
    app: {{ template "minio.name" . }}-update-prometheus-secret
    chart: {{ template "minio.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
rules:
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - get
      - create
      - update
      - patch
    resourceNames:
    {{- if .Values.metrics.serviceMonitor.enabled }}
      - {{ $fullName }}-servicemonitor-prometheus
    {{- end }}
    {{- if .Values.metrics.podMonitor.enabled }}
      - {{ $fullName }}-podmonitor-prometheus
    {{- end}}
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - create
  - apiGroups:
      - monitoring.coreos.com
    resources:
    {{- if .Values.metrics.serviceMonitor.enabled }}
      - servicemonitors
    {{- end}}
    {{- if .Values.metrics.podMonitor.enabled }}
      - podmonitors
    {{- end}}
    verbs:
      - get
    resourceNames:
      - {{ $fullName }}
{{- end -}}