{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ template "victoria-metrics.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
  {{- include "victoria-metrics.common.metaLabels" . | nindent 4 }}
  {{- if .Values.rbac.extraLabels }}
{{ toYaml .Values.rbac.extraLabels | indent 4}}
  {{- end }}
{{- with .Values.rbac.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
rules:
{{- if and .Values.rbac.pspEnabled (.Capabilities.APIVersions.Has "policy/v1beta1") }}
- apiGroups:      ['extensions']
  resources:      ['podsecuritypolicies']
  verbs:          ['use']
  resourceNames:  [{{ template "victoria-metrics.fullname" . }}]
{{- else }}
rules: []
{{- end }}
{{- end }}