apiVersion: batch/v1
kind: Job
metadata:
  name: {{ include "mev-inspect-backfill.fullname" . }}-{{ randAlphaNum 5 | lower }}
  labels:
    {{- include "mev-inspect-backfill.labels" . | nindent 4 }}
spec:
  completions: 1
  parallelism: 1
  ttlSecondsAfterFinished: 5
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - poetry
            - run
            - inspect-many-blocks
            - {{ .Values.command.startBlockNumber | quote }}
            - {{ .Values.command.endBlockNumber | quote }}
          env:
          - name: POSTGRES_HOST
            valueFrom:
              secretKeyRef:
                name: mev-inspect-db-credentials
                key: host
          - name: POSTGRES_USER
            valueFrom:
              secretKeyRef:
                name: mev-inspect-db-credentials
                key: username
          - name: POSTGRES_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mev-inspect-db-credentials
                key: password
          - name: TRACE_DB_HOST
            valueFrom:
              secretKeyRef:
                name: trace-db-credentials
                key: host
                optional: true
          - name: TRACE_DB_USER
            valueFrom:
              secretKeyRef:
                name: trace-db-credentials
                key: username
                optional: true
          - name: TRACE_DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: trace-db-credentials
                key: password
                optional: true
          - name: RPC_URL
            valueFrom:
              configMapKeyRef:
                name: mev-inspect-rpc
                key: url
      restartPolicy: OnFailure
