{{- if and ( .Values.ingressMonitorController.rbac.create ) (eq .Values.ingressMonitorController.watchNamespace "") }}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
{{- if .Values.ingressMonitorController.useFullName }}
  name: {{ template "fullname" . }}-role-binding
{{- else }}
  name: {{ template "name" . }}-role-binding
{{- end }}
  labels:
    app: {{ template "name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
{{- if .Values.ingressMonitorController.rbac.labels }}
{{ toYaml .Values.ingressMonitorController.rbac.labels | indent 4 }}
{{- end }}
{{- if .Values.ingressMonitorController.matchLabels }}
{{ toYaml .Values.ingressMonitorController.matchLabels | indent 4 }}
{{- end }}
roleRef:
  kind: ClusterRole
{{- if .Values.ingressMonitorController.useFullName }}
  name: {{ template "fullname" . }}-role
{{- else }}
  name: {{ template "name" . }}-role
{{- end }}
  apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
  name: {{ template "serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
{{- end }}