---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: cloud-controller-manager
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: system:cloud-controller-manager
  labels:
    kubernetes.io/cluster-service: "true"
rules:
- apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - '*'

- apiGroups:
  - ""
  resources:
  - nodes/status
  verbs:
  - patch

- apiGroups:
  - ""
  resources:
  - services
  verbs:
  - list
  - watch
  - patch
  - get

- apiGroups:
  - ""
  resources:
  - services/status
  verbs:
  - patch
  - get
  - update

- apiGroups:
    - ""
  resources:
    - configmaps
  resourceNames:
    - "extension-apiserver-authentication"
  verbs:
    - get

- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - list
  - watch
  - create
  - patch
  - update

# For leader election
- apiGroups:
  - ""
  resources:
  - endpoints
  verbs:
  - create

- apiGroups:
  - ""
  resources:
  - endpoints
  resourceNames:
  - "cloud-controller-manager"
  verbs:
  - get
  - list
  - watch
  - update

- apiGroups:
  - ""
  resources:
  - configmaps
  verbs:
  - create

- apiGroups:
    - "coordination.k8s.io"
  resources:
    - leases
  verbs:
    - get
    - create
    - update
    - delete
    - patch
    - watch

- apiGroups:
  - ""
  resources:
  - configmaps
  resourceNames:
  - "cloud-controller-manager"
  verbs:
  - get
  - update

- apiGroups:
    - ""
  resources:
    - configmaps
  resourceNames:
    - "extension-apiserver-authentication"
  verbs:
    - get
    - list
    - watch

- apiGroups:
  - ""
  resources:
  - serviceaccounts
  verbs:
  - create
  - list
  - get
  - watch
- apiGroups:
  - ""
  resources:
  - secrets
  verbs:
  - get
  - list

# For the PVL
- apiGroups:
  - ""
  resources:
  - persistentvolumes
  verbs:
  - list
  - watch
  - patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: oci-cloud-controller-manager
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:cloud-controller-manager
subjects:
- kind: ServiceAccount
  name: cloud-controller-manager
  namespace: kube-system
