{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
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 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ template "victoria-metrics.fullname" . }}
subjects:
- kind: ServiceAccount
  name: {{ template "victoria-metrics.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
{{- end -}}