{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if .Values.rbac.create }}
kind: ClusterRole
apiVersion: {{ include "common.capabilities.rbac.apiVersion" . }}
metadata:
  name: {{ include "common.names.fullname.namespace" . }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: envoy-gateway
    app.kubernetes.io/component: envoy-gateway
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
rules:
  - apiGroups:
      - ""
    resources:
      - nodes
      - namespaces
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - gateway.networking.k8s.io
    resources:
      - gatewayclasses
    verbs:
      - get
      - list
      - patch
      - update
      - watch
  - apiGroups:
      - gateway.networking.k8s.io
    resources:
      - gatewayclasses/status
    verbs:
      - update
  - apiGroups:
      - multicluster.x-k8s.io
    resources:
      - serviceimports
    verbs:
      - get
      - list
      - watch
  {{- if .Values.watchAllNamespaces }}
  - apiGroups:
      - ""
    resources:
      - configmaps
      - secrets
      - services
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - apps
    resources:
      - deployments
      - daemonsets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - discovery.k8s.io
    resources:
      - endpointslices
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - gateway.envoyproxy.io
    resources:
      - envoyproxies
      - envoypatchpolicies
      - clienttrafficpolicies
      - backendtrafficpolicies
      - securitypolicies
      - envoyextensionpolicies
      - backends
      - httproutefilters
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - gateway.envoyproxy.io
    resources:
      - envoypatchpolicies/status
      - clienttrafficpolicies/status
      - backendtrafficpolicies/status
      - securitypolicies/status
      - envoyextensionpolicies/status
      - backends/status
    verbs:
      - update
  - apiGroups:
      - gateway.networking.k8s.io
    resources:
      - gateways
      - grpcroutes
      - httproutes
      - referencegrants
      - tcproutes
      - tlsroutes
      - udproutes
      - backendtlspolicies
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - gateway.networking.k8s.io
    resources:
      - gateways/status
      - grpcroutes/status
      - httproutes/status
      - tcproutes/status
      - tlsroutes/status
      - udproutes/status
      - backendtlspolicies/status
    verbs:
      - update
  {{- if .Values.topologyInjector.enabled }}
  - apiGroups:
      - ""
    resources:
      - pods
      - pods/binding
    verbs:
      - get
      - list
      - patch
      - update
      - watch
  {{- end }}
  {{- end }}
  {{- if .Values.rbac.rules }}
  {{- include "common.tplvalues.render" ( dict "value" .Values.rbac.rules "context" $ ) | nindent 2 }}
  {{- end }}
{{- end }}
