apiVersion: batch/v1
kind: Job
metadata:
  name: {{ include "vertical-pod-autoscaler.crds.fullname" . }}
  labels:
    {{- include "vertical-pod-autoscaler.crds.labels" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  annotations:
    helm.sh/hook: pre-install,pre-upgrade
    helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
spec:
  template:
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "vertical-pod-autoscaler.crds.fullname" . }}
      containers:
        - name: kubectl
          image: "{{ .Values.crds.image.repository }}:{{ .Values.crds.image.tag }}"
          imagePullPolicy: {{ .Values.crds.image.pullPolicy }}
          args:
            - apply
            {{- range $path, $_ := .Files.Glob  "files/crds/*" }}
            - --filename=/config/{{ base $path }}
            {{- end }}
          volumeMounts:
            - name: config
              mountPath: /config
              readOnly: true
      {{- with .Values.crds.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.crds.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.crds.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      restartPolicy: Never
      volumes:
        - name: config
          configMap:
            name: {{ include "vertical-pod-autoscaler.crds.fullname" . }}
