---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: cilium
rules:
- apiGroups:
  - networking.k8s.io
  resources:
{% if cilium_version | regex_replace('v') is version('1.7', '<') %}
  - ingresses
{% endif %}
  - networkpolicies
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - discovery.k8s.io
  resources:
  - endpointslices
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - namespaces
  - services
  - nodes
  - endpoints
{% if cilium_version | regex_replace('v') is version('1.7', '<') %}
  - componentstatuses
{% endif %}
  verbs:
  - get
  - list
  - watch
{% if cilium_version | regex_replace('v') is version('1.7', '<') %}
- apiGroups:
  - extensions
  resources:
  - ingresses
  verbs:
  - create
  - get
  - list
  - watch
{% endif %}
{% if cilium_version | regex_replace('v') is version('1.7', '>') %}
- apiGroups:
  - ""
  resources:
  - pods/finalizers
  verbs:
  - update
{% endif %}
- apiGroups:
  - ""
  resources:
  - pods
  - nodes
  verbs:
  - get
  - list
  - watch
  - update
- apiGroups:
  - ""
  resources:
  - nodes
  - nodes/status
  verbs:
  - patch
- apiGroups:
  - apiextensions.k8s.io
  resources:
  - customresourcedefinitions
  verbs:
  - create
  - get
  - list
  - watch
  - update
- apiGroups:
  - cilium.io
  resources:
  - ciliumnetworkpolicies
  - ciliumnetworkpolicies/status
{% if cilium_version | regex_replace('v') is version('1.7', '>=') %}
  - ciliumclusterwidenetworkpolicies
  - ciliumclusterwidenetworkpolicies/status
{% endif %}
  - ciliumendpoints
  - ciliumendpoints/status
{% if cilium_version | regex_replace('v') is version('1.6', '>=') %}
  - ciliumnodes
  - ciliumnodes/status
  - ciliumidentities
  - ciliumidentities/status
{% endif %}
{% if cilium_version | regex_replace('v') is version('1.9', '>=') %}
  - ciliumnetworkpolicies/finalizers
  - ciliumclusterwidenetworkpolicies/finalizers
  - ciliumendpoints/finalizers
  - ciliumnodes/finalizers
  - ciliumidentities/finalizers
  - ciliumlocalredirectpolicies
  - ciliumlocalredirectpolicies/status
  - ciliumlocalredirectpolicies/finalizers
{% endif %}
{% if cilium_version | regex_replace('v') is version('1.10', '>=') %}
  - ciliumegressnatpolicies
{% endif %}
{% if cilium_version | regex_replace('v') is version('1.11', '>=') %}
  - ciliumendpointslices
{% endif %}
{% if cilium_version | regex_replace('v') is version('1.12', '>=') %}
  - ciliumbgploadbalancerippools
  - ciliumbgppeeringpolicies
{% endif %}
  verbs:
  - '*'
{% if cilium_version | regex_replace('v') is version('1.12', '>=') %}
- apiGroups:
  - cilium.io
  resources:
  - ciliumclusterwideenvoyconfigs
  - ciliumenvoyconfigs
  verbs:
  - list
  - watch
{% endif %}
