{{- if .Values.seed.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ include "openstack-api-simulator.fullname" . }}-seed
  labels:
    {{- include "openstack-api-simulator.labels" . | nindent 4 }}
    app.kubernetes.io/component: seed
  annotations:
    "helm.sh/hook": post-install,post-upgrade
    "helm.sh/hook-weight": "5"
    "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
  backoffLimit: {{ .Values.seed.backoffLimit }}
  template:
    metadata:
      labels:
        {{- include "openstack-api-simulator.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: seed
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "openstack-api-simulator.serviceAccountName" . }}
      restartPolicy: OnFailure
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: seed
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: {{ include "openstack-api-simulator.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: {{ include "openstack-api-simulator.secretName" . }}
                  key: DATABASE_URL
            - name: SEED_PROFILE
              value: {{ .Values.seed.profile | quote }}
            - name: LOG_LEVEL
              value: {{ .Values.config.logLevel | quote }}
          command:
            - python
            - -m
            - app.openstack.seed_cli
            - --profile
            - {{ .Values.seed.profile | quote }}
          resources:
            {{- toYaml .Values.seed.resources | nindent 12 }}
          volumeMounts:
            - name: tmp
              mountPath: /tmp
      volumes:
        - name: tmp
          emptyDir: {}
{{- end }}
