ttlSecondsAfterFinished and Kubernetes 1.20

604 Views Asked by At

So, I created sample job from the docs:

apiVersion: batch/v1beta1
kind: Job
metadata:
  name: pi-with-ttl
  namespace: ish
spec:
  ttlSecondsAfterFinished: 100
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never

And I don't see ttlSecondsAfterFinished there

kubectl -n ish get job.batch/pi-with-ttl -o yaml

apiVersion: batch/v1
kind: Job
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"name":"pi-with-ttl","namespace":"ish"},"spec":{"template":{"spec":{"containers":[{"command":["perl","-Mbignum=bpi","-wle","print bpi(2000)"],"image":"perl:5.34.0","name":"pi"}],"restartPolicy":"Never"}},"ttlSecondsAfterFinished":100}}
  creationTimestamp: "2023-04-26T19:35:20Z"
  labels:
    controller-uid: 4bf27c42-ac18-4fb3-a5f2-6cccf6b495a6
    job-name: pi-with-ttl
  name: pi-with-ttl
  namespace: ish
  resourceVersion: "231774076"
  uid: 4bf27c42-ac18-4fb3-a5f2-6cccf6b495a6
spec:
  backoffLimit: 6
  completions: 1
  parallelism: 1
  selector:
    matchLabels:
      controller-uid: 4bf27c42-ac18-4fb3-a5f2-6cccf6b495a6
  template:
    metadata:
      creationTimestamp: null
      labels:
        controller-uid: 4bf27c42-ac18-4fb3-a5f2-6cccf6b495a6
        job-name: pi-with-ttl
    spec:
      containers:
      - command:
        - perl
        - -Mbignum=bpi
        - -wle
        - print bpi(2000)
        image: perl:5.34.0
        imagePullPolicy: IfNotPresent
        name: pi
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Never
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  completionTime: "2023-04-26T19:36:10Z"
  conditions:
  - lastProbeTime: "2023-04-26T19:36:10Z"
    lastTransitionTime: "2023-04-26T19:36:10Z"
    status: "True"
    type: Complete
  startTime: "2023-04-26T19:35:20Z"
  succeeded: 1

Job lives forever

NAME                    COMPLETIONS   DURATION   AGE
job.batch/pi-with-ttl   1/1           50s        19h

At the same time I have sample cronjob with ttlSecondsAfterFinished and it's working as expected.

kubectl -n ish cronjob platform-core-base-auto-check-in -o yaml

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  annotations:
---
spec:
  ttlSecondsAfterFinished: 86400

Am I missing something?

1

There are 1 best solutions below

0
Rick Rackow On

I'd recommend upgrading. This wasn't stable back then and with everything that's beta "there may be dragons"

You can read more about the expectations towards beta versions here