{{- if and .Values.forwarder.enabled .Values.forwarder.rbac.create }}
apiVersion: {{ include "common.capabilities.rbac.apiVersion" . }}
kind: ClusterRole
metadata:
  name: {{ include "common.names.fullname.namespace" . }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
rules:
  - apiGroups:
      - ""
    resources:
      - "namespaces"
      - "pods"
    verbs:
      - "get"
      - "watch"
      - "list"
  {{- $pspAvailable := (semverCompare "<1.25-0" (include "common.capabilities.kubeVersion" .)) -}}
  {{- if and $pspAvailable .Values.forwarder.rbac.pspEnabled }}
  - apiGroups:
      - "policy"
    resources:
      - "podsecuritypolicies"
    resourceNames:
      - {{ printf "%s-%s" (include "common.names.fullname.namespace" .) "forwarder" | trunc 63 | trimSuffix "-" }}
    verbs:
      - "use"
  {{- end }}
{{- end }}
