# Preview-only TiDB mirror synchronization job using the shared source-mirror
# PVC. This job owns only /code-cache/mirrors/pingcap-tidb.git; future
# repositories must use separate jobs and separate mirror/status paths while
# mounting the same PVC.
#
# Keep this CronJob suspended until the first full bare mirror has been
# bootstrapped and verified manually. The backend does not mount this PVC in
# this PR, so a failed bootstrap cannot affect the running application.
apiVersion: batch/v1
kind: CronJob
metadata:
  name: tidb-mirror-sync-daily
  labels:
    app: tidb-mirror-sync
spec:
  schedule: "20 3 * * *"
  timeZone: "Asia/Shanghai"
  suspend: false
  concurrencyPolicy: Forbid
  startingDeadlineSeconds: 3600
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      backoffLimit: 1
      ttlSecondsAfterFinished: 86400
      activeDeadlineSeconds: 7200
      template:
        metadata:
          labels:
            app: tidb-mirror-sync
        spec:
          serviceAccountName: investibook-backend
          restartPolicy: Never
          affinity:
            podAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                - labelSelector:
                    matchExpressions:
                      - key: app
                        operator: In
                        values:
                          - backend
                  topologyKey: kubernetes.io/hostname
          containers:
            - name: tidb-mirror-sync
              image: investibook/backend:latest
              imagePullPolicy: IfNotPresent
              command:
                - uv
                - run
                - python
                - -m
                - investibook.scripts.sync_tidb_mirror
              envFrom:
                - configMapRef:
                    name: investibook-backend-config
                    optional: true
              env:
                - name: DATA_DIR
                  value: /data
                - name: INVESTIBOOK_CODE_CONTEXT_CACHE_DIR
                  value: /code-cache
                - name: INVESTIBOOK_CODE_MIRROR_PVC_HIGH_WATERMARK_RATIO
                  value: "0.80"
                - name: INVESTIBOOK_CODE_MIRROR_SYNC_TIMEOUT_SECONDS
                  value: "3600"
              volumeMounts:
                - name: data
                  mountPath: /data
                - name: code-cache
                  mountPath: /code-cache
              resources:
                requests:
                  cpu: "250m"
                  memory: "512Mi"
                limits:
                  cpu: "2000m"
                  memory: "2Gi"
          volumes:
            - name: data
              persistentVolumeClaim:
                claimName: investibook-data
            - name: code-cache
              persistentVolumeClaim:
                claimName: investibook-code-cache
