# infrastructure/kubernetes/base/cronjobs/external-data-rotation-cronjob.yaml
# Monthly CronJob to rotate 24-month sliding window (runs 1st of month at 2am UTC)
apiVersion: batch/v1
kind: CronJob
metadata:
  name: external-data-rotation
  namespace: bakery-ia
  labels:
    app: external-service
    component: data-rotation
spec:
  schedule: "0 2 1 * *"

  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3

  concurrencyPolicy: Forbid

  jobTemplate:
    metadata:
      labels:
        app: external-service
        job: data-rotation
    spec:
      ttlSecondsAfterFinished: 172800
      backoffLimit: 2

      template:
        metadata:
          labels:
            app: external-service
            cronjob: data-rotation
        spec:
          restartPolicy: OnFailure

          containers:
          - name: data-rotator
            image: bakery/external-service:latest
            imagePullPolicy: Always

            command:
              - python
              - -m
              - app.jobs.rotate_data

            args:
              - "--log-level=INFO"
              - "--notify-slack=true"

            envFrom:
            - configMapRef:
                name: bakery-config
            - secretRef:
                name: database-secrets
            - secretRef:
                name: external-api-secrets
            - secretRef:
                name: monitoring-secrets

            resources:
              requests:
                memory: "512Mi"
                cpu: "250m"
              limits:
                memory: "1Gi"
                cpu: "500m"
