{{- if .Values.apiPriority.enabled }}
apiVersion: flowcontrol.apiserver.k8s.io/v1
kind: FlowSchema
metadata:
  name: {{ include "flux-operator.fullname" . }}
  annotations:
    apf.kubernetes.io/autoupdate-spec: "false"
spec:
  distinguisherMethod:
    type: ByUser
  matchingPrecedence: 950
  priorityLevelConfiguration:
    name: {{ .Values.apiPriority.level }}
  rules:
    - nonResourceRules:
        - nonResourceURLs:
            - '*'
          verbs:
            - '*'
      resourceRules:
        - apiGroups:
            - '*'
          clusterScope: true
          namespaces:
            - '*'
          resources:
            - '*'
          verbs:
            - '*'
      subjects:
        - kind: ServiceAccount
          serviceAccount:
            name: {{ include "flux-operator.serviceAccountName" . }}
            namespace: {{ .Release.Namespace }}
        {{- range .Values.apiPriority.extraServiceAccounts }}
        - kind: ServiceAccount
          serviceAccount:
            name: {{ .name }}
            namespace: {{ .namespace }}
        {{- end }}
{{- end }}
