apiVersion: v1
kind: ServiceAccount
metadata:
  annotations:
    "helm.sh/hook": "test"
    "helm.sh/hook-delete-policy": "hook-succeeded,before-hook-creation,hook-failed"
  name: {{ include "vpa.fullname" . }}-test
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ include "vpa.fullname" . }}-test
  labels:
    {{- include "vpa.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": "test"
    "helm.sh/hook-delete-policy": "hook-succeeded,before-hook-creation,hook-failed"
rules:
  - apiGroups:
      - "metrics.k8s.io"
    resources:
      - "nodes"
    verbs:
      - list
  - apiGroups:
      - "apiextensions.k8s.io"
    resources:
      - customresourcedefinitions
    resourceNames:
      - verticalpodautoscalercheckpoints.autoscaling.k8s.io
      - verticalpodautoscalers.autoscaling.k8s.io
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - admissionregistration.k8s.io
    resources:
      - mutatingwebhookconfigurations
    resourceNames:
      - {{ include "vpa.fullname" . }}-webhook-config
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ include "vpa.fullname" . }}-test
  labels:
    {{- include "vpa.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": "test"
    "helm.sh/hook-delete-policy": "hook-succeeded,before-hook-creation,hook-failed"
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ include "vpa.fullname" . }}-test
subjects:
  - kind: ServiceAccount
    name: {{ include "vpa.fullname" . }}-test
    namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ include "vpa.fullname" . }}-test
  labels:
    {{- include "vpa.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": "test"
    "helm.sh/hook-delete-policy": "hook-succeeded,before-hook-creation,hook-failed"
rules:
  - apiGroups:
      - "autoscaling.k8s.io"
    resources:
      - verticalpodautoscalers
    verbs:
      - get
      - list
      - watch
      - create
      - delete
  - apiGroups:
      - "autoscaling.k8s.io"
    resources:
      - verticalpodautoscalercheckpoints
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - secrets
      - services
    resourceNames:
      - {{ include "vpa.fullname" . }}-webhook
      - {{ include "vpa.webhook.secret" . }}
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ include "vpa.fullname" . }}-test
  labels:
    {{- include "vpa.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": "test"
    "helm.sh/hook-delete-policy": "hook-succeeded,before-hook-creation,hook-failed"
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ include "vpa.fullname" . }}-test
subjects:
  - kind: ServiceAccount
    name: {{ include "vpa.fullname" . }}-test
    namespace: {{ .Release.Namespace }}
