# https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/
# https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#jobs-history-limits
# apiVersion: batch/v1
# Kubernetes v1.21 이전에는 beta api 사용
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: ysoftman-cronjob-test
spec:
  schedule: "*/5 * * * *"
  successfulJobsHistoryLimit: 5
  failedJobsHistoryLimit: 5
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: ysoftman-cronjob-test
            image: busybox
            imagePullPolicy: Always
            command:
            - /bin/sh
            - -c
            # for ((;;)) 는 sh 에서 지원하지 않아 while 사용
            - date; echo "wait for 60s"; i=1; while [ $i -le 60 ]; do echo $i; sleep 1; i=$((i+1)); done; echo "job completed\!"
            resources:
              limits:
                cpu: "500m"
                memory: "200Mi"
              requests:
                cpu: "250m"
                memory: "100Mi"
          restartPolicy: OnFailure
      backoffLimit: 1
