{{- if  and .Values.rbac.create  (not .Values.watchNamespace) -}}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ include "vm-operator.fullname" . }}
  labels:
{{ include "vm-operator.labels" . | indent 4 }}
{{- with .Values.extraLabels }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- with .Values.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
subjects:
- kind: ServiceAccount
  name: {{ template "vm-operator.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
roleRef:
  kind: ClusterRole
  name: {{ include "vm-operator.fullname" . }}
  apiGroup: rbac.authorization.k8s.io
{{- end -}}
