---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: vpa-recommender
  namespace: vpa-system
---
# Read pods from the metrics API (metrics-server) to build recommendations.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: vpa-system:metrics-reader
rules:
  - apiGroups: ["metrics.k8s.io"]
    resources: ["pods"]
    verbs: ["get", "list"]
---
# Watch pods/nodes/limitranges and VPA objects; emit events.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: vpa-system:actor
rules:
  - apiGroups: [""]
    resources: ["pods", "nodes", "limitranges"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["", "events.k8s.io"]
    resources: ["events"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
  - apiGroups: ["autoscaling.k8s.io"]
    resources: ["verticalpodautoscalers"]
    verbs: ["get", "list", "watch"]
---
# Write recommendations back to the VPA object's status subresource.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: vpa-system:status-actor
rules:
  - apiGroups: ["autoscaling.k8s.io"]
    resources: ["verticalpodautoscalers/status"]
    verbs: ["get", "patch"]
---
# Manage recommender checkpoints (recovery of history after restart).
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: vpa-system:checkpoint-actor
rules:
  - apiGroups: ["autoscaling.k8s.io"]
    resources: ["verticalpodautoscalercheckpoints"]
    verbs: ["get", "list", "watch", "create", "patch", "delete"]
  - apiGroups: [""]
    resources: ["namespaces"]
    verbs: ["get", "list"]
---
# Resolve VPA targetRef workloads and their scale subresource.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: vpa-system:target-reader
rules:
  - apiGroups: ["*"]
    resources: ["*/scale"]
    verbs: ["get", "watch"]
  - apiGroups: [""]
    resources: ["replicationcontrollers"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["apps"]
    resources: ["daemonsets", "deployments", "replicasets", "statefulsets"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["batch"]
    resources: ["jobs", "cronjobs"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: vpa-system:metrics-reader
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: vpa-system:metrics-reader
subjects:
  - kind: ServiceAccount
    name: vpa-recommender
    namespace: vpa-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: vpa-system:actor
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: vpa-system:actor
subjects:
  - kind: ServiceAccount
    name: vpa-recommender
    namespace: vpa-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: vpa-system:status-actor
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: vpa-system:status-actor
subjects:
  - kind: ServiceAccount
    name: vpa-recommender
    namespace: vpa-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: vpa-system:checkpoint-actor
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: vpa-system:checkpoint-actor
subjects:
  - kind: ServiceAccount
    name: vpa-recommender
    namespace: vpa-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: vpa-system:target-reader
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: vpa-system:target-reader
subjects:
  - kind: ServiceAccount
    name: vpa-recommender
    namespace: vpa-system
