apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: fxhnt-surfer-data
  namespace: foxhunt
spec:
  accessModes: ["ReadWriteOnce"]
  resources:
    requests:
      storage: 5Gi
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: fxhnt-forward
  namespace: foxhunt
  labels: { app.kubernetes.io/name: fxhnt-forward, app.kubernetes.io/part-of: foxhunt }
spec:
  schedule: "30 23 * * *"          # daily 23:30 UTC — matches the retired laptop cron
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      backoffLimit: 1
      template:
        metadata:
          labels: { app.kubernetes.io/part-of: foxhunt, app.kubernetes.io/name: fxhnt-forward }   # part-of -> postgres ingress/dns; name -> fxhnt-forward egress netpol
        spec:
          restartPolicy: Never
          nodeSelector:
            k8s.scaleway.com/pool-name: platform
          imagePullSecrets:
            - name: gitlab-registry
          containers:
            - name: ingest
              image: gitlab-registry.foxhunt.svc.cluster.local:5000/root/foxhunt/fxhnt-cockpit:latest   # set by CI / Kaniko push
              command: ["sh", "-c"]
              args:
                - |
                  set -e
                  fxhnt migrate-cockpit
                  fxhnt fetch --data-dir /data/surfer --crypto --no-futures
                  if [ "$(date -u +%u)" = "7" ]; then
                    fxhnt fetch --data-dir /data/surfer --no-crypto --futures
                  fi
                  fxhnt forward-track --data-dir /data/surfer --state /data/surfer/fxhnt_combined_forward.json
                  fxhnt ingest-forward --state-dir /data/surfer
              env:
                - name: FXHNT_OPERATIONAL_DSN
                  value: "postgresql+psycopg://foxhunt@postgres.foxhunt.svc.cluster.local:5432/fxhnt"
                - name: PGPASSWORD                       # libpq picks this up; password stays out of the DSN
                  valueFrom: { secretKeyRef: { name: db-credentials, key: password } }
                - name: DATABENTO_API_KEY
                  valueFrom: { secretKeyRef: { name: databento-credentials, key: api-key } }
                - name: FXHNT_DATABENTO_MAX_COST_USD
                  value: "40.0"
              volumeMounts:
                - { name: surfer-data, mountPath: /data }
          volumes:
            - name: surfer-data
              persistentVolumeClaim: { claimName: fxhnt-surfer-data }
