{{- if .Values.rbac.create -}}
{{- $ctx := dict "helm" . }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
{{- $ns := include "vm.namespace" $ctx }}
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ $fullname }}
  namespace: {{ $ns }}
  {{- $_ := set $ctx "extraLabels" .Values.extraLabels }}
  labels: {{ include "vm.labels" $ctx | nindent 4 }}
  {{- $_ := unset $ctx "extraLabels" }}
  {{- with .Values.annotations }}
  annotations: {{ toYaml . | nindent 4 }}
  {{- end }}
subjects:
- kind: ServiceAccount
  name: {{ (.Values.serviceAccount).name | default $fullname }}
  namespace: {{ $ns }}
roleRef:
  kind: Role
  name: {{ $fullname }}
  apiGroup: rbac.authorization.k8s.io
{{- end -}}
