# =============================================================================
# 備份還原驗證 CronJob — ADR-074 M4
# =============================================================================
# 每週日 02:00 台北（18:00 UTC 週六）執行 Velero restore dry-run。
# 失敗 → 寫入 node-exporter textfile → BackupRestoreTestFailed 告警。
#
# 前提：node-exporter 須掛載 /var/lib/node_exporter/textfile_collector
#       Velero CLI 需在 velero/velero image 中可用
#
# 2026-04-12 ogt (ADR-074 M4)
# =============================================================================

apiVersion: batch/v1
kind: CronJob
metadata:
  name: backup-restore-test
  namespace: velero
  labels:
    app: awoooi
    component: backup-restore-test
    adr: "074-m4"
spec:
  # 每週日 02:00 台北 = 週六 18:00 UTC
  schedule: "0 18 * * 6"
  timeZone: "Asia/Taipei"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 5
  startingDeadlineSeconds: 600
  jobTemplate:
    spec:
      backoffLimit: 0
      activeDeadlineSeconds: 600
      template:
        metadata:
          labels:
            app: awoooi
            component: backup-restore-test
        spec:
          restartPolicy: Never
          serviceAccountName: velero
          containers:
            - name: backup-restore-test
              image: velero/velero:v1.13.0
              command:
                - /bin/sh
                - /scripts/cron_backup_restore_test.sh
              env:
                - name: TZ
                  value: "Asia/Taipei"
                - name: VELERO_NAMESPACE
                  value: "velero"
                - name: VELERO_BACKUP_NAME
                  value: "awoooi-daily"
              volumeMounts:
                - name: scripts
                  mountPath: /scripts
                  readOnly: true
                - name: textfile-collector
                  mountPath: /var/lib/node_exporter/textfile_collector
              resources:
                requests:
                  cpu: "50m"
                  memory: "64Mi"
                limits:
                  cpu: "200m"
                  memory: "128Mi"
          volumes:
            - name: scripts
              configMap:
                name: backup-restore-test-scripts
                defaultMode: 0755
            - name: textfile-collector
              hostPath:
                path: /var/lib/node_exporter/textfile_collector
                type: DirectoryOrCreate
