---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: sdn-controller
  namespace: openshift-sdn

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: openshift-sdn-controller
rules:
- apiGroups: [""]
  resources:
  - namespaces
  verbs:
  - list
  - get
  - watch
- apiGroups: ["network.openshift.io"]
  resources:
  - clusternetworks
  - egressnetworkpolicies
  - hostsubnets
  - netnamespaces
  verbs:
  - get
  - list
  - watch
  - create
  - update
  - patch
  - delete
- apiGroups: [""]
  resources:
  - nodes
  verbs:
  - list
  - get
  - watch
- apiGroups: [""]
  resources:
  - "nodes/status"
  verbs:
  - patch
  - update

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: openshift-sdn-controller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: openshift-sdn-controller
subjects:
- kind: ServiceAccount
  name: sdn-controller
  namespace: openshift-sdn

---
# Only grant access to the specific config map for leader election
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: openshift-sdn-controller-leaderelection
  namespace: openshift-sdn
rules:
- apiGroups: [""]
  resources:
  - configmaps
  verbs:
  - create
  - update
  - patch
  - get
  - list
  - watch
- apiGroups: [""]
  resources:
  - events
  verbs:
  - create
  - patch
  - update

---
# Bind leader-election access
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: openshift-sdn-controller-leaderelection
  namespace: openshift-sdn
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: openshift-sdn-controller-leaderelection
subjects:
- kind: ServiceAccount
  name: sdn-controller
  namespace: openshift-sdn
