Search code examples
dockercronopenshift

Unsupported value: "Always": supported values: "OnFailure", "Never"


I am trying to set up a Cron Job in OpenShift but it fails with the following message:

2020-02-27T14:01:18.7412341Z * spec.jobTemplate.spec.template.spec.containers: Required value 2020-02-27T14:01:18.7412503Z * spec.jobTemplate.spec.template.spec.restartPolicy: Unsupported value: "Always": supported values: "OnFailure", "Never"

and my CronJob-file goes as this:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: my-cjob
  labels:
    job-name: my-cjob
spec:
  schedule: "*/5 * * * *" 
  jobTemplate:
    spec:
      template:         
        metadata:
          name: my-cjob
          labels:
          job-name: my-cjob
        spec:
          containers:
          - name: my-cjob
            image: my-image-name
          restartPolicy: OnFailure

What am I doing wrong? I have taken great inspiration from OpenShift:

snippet from OpenShifts own site

found here: https://access.redhat.com/documentation/en-us/openshift_container_platform/3.11/html/developer_guide/dev-guide-cron-jobs

What am I not seeing?


Solution

  • Found the answer... A bit confusing, especially when reading the error message, but Suresh Vishnoi was right:

    It all came down to a missing "tab" / indent:

    apiVersion: batch/v1beta1
    kind: CronJob
    metadata:
      name: my-cjob
      labels:
        job-name: my-cjob
    spec:
      schedule: "*/5 * * * *" 
      jobTemplate:
        spec:
          template:         
            metadata:
              name: my-cjob
              labels:
                job-name: my-cjob   <<<< Here was the missing indent!
            spec:
              containers:
              - name: my-cjob
                image: my-image-name
              restartPolicy: OnFailure
    

    My theory is that the missing indent had confused the error-handler and therefore it for some reason thought the issue was in regards to the next step, the containers.

    I'll leave this here if anyone else should be hitting this (stupid) error message and think that it has anything to do with containers or restartpolicy...