{{- if and .Values.rbac.create (not .Values.scope.enabled) -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: {{ template "nginx-ingress.fullname" . }}
  labels: {{- include "nginx-ingress.labels" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "nginx-ingress.tplValue" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "nginx-ingress.annotations" (dict "annotations" .Values.commonAnnotations "context" $) | trim | nindent 4 }}
  {{- end }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "nginx-ingress.fullname" . }}
subjects:
  - kind: ServiceAccount
    name: {{ template "nginx-ingress.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
{{- end -}}
