Kubernetes using wrong value for restartPolicy

8/27/2018

I'm trying a Job deployment in kubernetes with the configuration below but I'm getting this error :

spec.template.spec.restartPolicy: Unsupported value: "Always": supported values: OnFailure, Never

It's like kubernetes doesn't read my restartPolicy configuration (set to never) or it's overridden somewhere...

The "funny" thing is it's working for my Cronjob deployment (I'm using the same template for both of them).

Kubernetes version : 1.7.7

Here is my configuration :

{
  "apiVersion": "batch/v1",
  "kind": "Job",
  "metadata": {
    "name": "pipeline-test",
    "labels": {
      "app": "pipeline-test",
      "env": "test",
      "commit": "xxxxxxxx"
    },
    "namespace": "pipeline-test"
  },
  "spec": {
    "jobTemplate": {
      "spec": {
        "template": {
          "metadata": {
            "labels": {
              "app": "pipeline-test",
              "env": "test",
              "commit": "xxxxxxxx"
            }
          },
          "spec": {
            "restartPolicy": "Never",
            "containers": [
              {
                "name": "pipeline-test",
                "image": "us.gcr.io/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "env": [
                  {
                    "name": "APP_ENV",
                    "value": "test"
                  },
                  {
                    "name": "MAX_WORKERS",
                    "value": "2"
                  },
                  {
                    "name": "TYPE_CASTING",
                    "value": "false"
                  },
                  {
                    "name": "ENV",
                    "value": "test"
                  },
                  {
                    "name": "PROJECT_NAME",
                    "value": "null-testing1-v"
                  },
                  {
                    "name": "JOB_NAME",
                    "value": "testjob"
                  },
                  {
                    "name": "SUBSCRIPTION_NAME",
                    "value": "testsub"
                  },
                  {
                    "name": "CACHE_INVALIDATOR",
                    "value": "14-1"
                  },
                  {
                    "name": "GIT_COMMIT",
                    "value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                  },
                  {
                    "name": "APP_GIT_COMMIT",
                    "value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                  },
                  {
                    "name": "APP_NAME",
                    "value": "pipeline-test"
                  },
                ],
                "volumeMounts": [

                ],
                "ports": [
                  {
                    "containerPort": 3000
                  }
                ],
                "resources": {
                  "requests": {
                    "cpu": "100m",
                    "memory": "512Mi"
                  },
                  "limits": {
                    "cpu": "1000m",
                    "memory": "512Mi"
                  }
                }
              }
            ],
            "volumes": [

            ],
            "imagePullSecrets": [
              {
                "name": "image-pull-secret"
              }
            ]
          }
        }
      }
    }
  }
}

Thanks

EDIT : I was able to run it by removing 2 lines :

    "jobTemplate": {
      "spec": {

And so the restartPolicy was at the wrong level in the json and wasn't read.

-- Skullone
kubectl
kubernetes

1 Answer

8/27/2018

I was able to run it by removing 2 lines :

"jobTemplate": {
  "spec": {

And so the restartPolicy was at the wrong level in the json and wasn't read.

-- Skullone
Source: StackOverflow