# RBAC for the bin-pack-scheduler. Reuses the built-in system:kube-scheduler
# and system:volume-scheduler ClusterRoles (track upstream across k8s versions)
# and adds get/update on our own leader-election Lease, which system:kube-scheduler
# scopes to resourceName "kube-scheduler" only.
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: bin-pack-scheduler
  namespace: kube-system
  labels:
    osdc.io/module: bin-pack-scheduler
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: bin-pack-scheduler
  labels:
    osdc.io/module: bin-pack-scheduler
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:kube-scheduler
subjects:
  - kind: ServiceAccount
    name: bin-pack-scheduler
    namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: bin-pack-scheduler-volume
  labels:
    osdc.io/module: bin-pack-scheduler
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:volume-scheduler
subjects:
  - kind: ServiceAccount
    name: bin-pack-scheduler
    namespace: kube-system
---
# Lets the scheduler read the extension-apiserver-authentication ConfigMap so
# its HTTPS serving port (10259) can set up delegated auth cleanly on startup.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: bin-pack-scheduler-auth-reader
  namespace: kube-system
  labels:
    osdc.io/module: bin-pack-scheduler
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: extension-apiserver-authentication-reader
subjects:
  - kind: ServiceAccount
    name: bin-pack-scheduler
    namespace: kube-system
---
# Lease create is already granted cluster-wide by system:kube-scheduler;
# get/update on our custom lease name is not, so grant it here.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: bin-pack-scheduler-lease
  namespace: kube-system
  labels:
    osdc.io/module: bin-pack-scheduler
rules:
  - apiGroups: ["coordination.k8s.io"]
    resources: ["leases"]
    resourceNames: ["bin-pack-scheduler"]
    verbs: ["get", "update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: bin-pack-scheduler-lease
  namespace: kube-system
  labels:
    osdc.io/module: bin-pack-scheduler
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: bin-pack-scheduler-lease
subjects:
  - kind: ServiceAccount
    name: bin-pack-scheduler
    namespace: kube-system
