# =============================================================================
# K3s Status Report CronJob - Phase 21.2 定期報告
# =============================================================================
# 每日 09:00 台北 (01:00 UTC) 發送 K3s 叢集狀態到 Telegram
#
# 2026-03-31 Claude Code (ADR-041)
# =============================================================================

apiVersion: batch/v1
kind: CronJob
metadata:
  name: k3s-status-report
  namespace: awoooi-prod
  labels:
    app: awoooi
    component: k3s-report
    phase: "21.2"
spec:
  # 每日 01:00 UTC = 09:00 台北
  schedule: "0 1 * * *"
  # 時區設定 (K8s 1.27+)
  timeZone: "Asia/Taipei"
  # 並發策略: 禁止並發執行
  concurrencyPolicy: Forbid
  # 保留歷史
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  # 錯過執行的處理 (最多延遲 5 分鐘)
  startingDeadlineSeconds: 300
  jobTemplate:
    spec:
      # 失敗重試
      backoffLimit: 2
      # 執行超時 (5 分鐘)
      activeDeadlineSeconds: 300
      template:
        metadata:
          labels:
            app: awoooi
            component: k3s-report
        spec:
          restartPolicy: OnFailure
          containers:
            - name: k3s-report
              # 2026-05-05 Codex: keep the API image placeholder so CD
              # injects the same immutable tag used by API/worker. The old
              # awoooi-api:latest repo returns 400 from Harbor after reboot.
              image: 192.168.0.110:5000/library/api:IMAGE_TAG_PLACEHOLDER
              imagePullPolicy: IfNotPresent
              command:
                - python
                - -m
                - src.services.k3s_monitor_service
              env:
                - name: TZ
                  value: "Asia/Taipei"
              envFrom:
                - configMapRef:
                    name: awoooi-config
                - secretRef:
                    name: awoooi-secrets
              resources:
                requests:
                  cpu: "50m"
                  memory: "64Mi"
                limits:
                  cpu: "200m"
                  memory: "128Mi"
          # 2026-05-05 Codex: this report only calls Prometheus and Telegram.
          # The old awoooi-api ServiceAccount does not exist, which prevented
          # Job pods from being created after reboot.
          serviceAccountName: default
