kubernetesansibleopenshift-3

oc / kubernetes: deployment returns "unrecognized type: string" while adding environment variables


We are deploying with Ansible scripts to Openshift 3 using oc apply. When we change template to add more environment variables, we receive a very vague error: "unrecognized type: string" and status code 500.

Setting --loglevel 10 leads to no more details:

$ /usr/local/bin/oc_v3.11.715 apply -f \"/tmp/ansible.YtEqVm_deploy/app.yml.json\" -n test-env --loglevel 10 2&> log.log

(several GET to get secret, deploymentconfigs, etc.)
...
I0127 11:49:05.455217     605 request.go:897] Request Body: {xxxxxxxx}
I0127 11:49:05.455280     605 round_trippers.go:386] curl -k -v -XPATCH  -H "User-Agent: oc_v3.11.715/v1.11.0+d4cacc0 (linux/amd64) kubernetes/d4cacc0" -H "Authorization: Bearer xxxxxx" -H "Accept: application/json" -H "Content-Type: application/strategic-merge-patch+json" 'https://test-env:8443/apis/apps.openshift.io/v1/namespaces/test-app/deploymentconfigs/app'
I0127 11:49:05.466278     605 round_trippers.go:405] PATCH https://test-env:8443/apis/apps.openshift.io/v1/namespaces/test-env-app/deploymentconfigs/app 500 Internal Server Error in 10 milliseconds
I0127 11:49:05.466287     605 round_trippers.go:411] Response Headers:
I0127 11:49:05.466291     605 round_trippers.go:414]     Content-Length: 118
I0127 11:49:05.466294     605 round_trippers.go:414]     Date: Fri, 27 Jan 2023 09:49:05 GMT
I0127 11:49:05.466297     605 round_trippers.go:414]     Audit-Id: 1d3f3398-14fc-4bfa-854b-6faf9b105680
I0127 11:49:05.466302     605 round_trippers.go:414]     Cache-Control: no-store
I0127 11:49:05.466307     605 round_trippers.go:414]     Content-Type: application/json
I0127 11:49:05.466321     605 request.go:897] Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"unrecognized type: string","code":500}
I0127 11:49:05.466603     605 helpers.go:201] server response object: [{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "unrecognized type: string",
  "code": 500
}]
F0127 11:49:05.466618     605 helpers.go:119] Error from server: unrecognized type: string

The request body is like:

{
    "metadata": {
        "annotations": {
            "kubectl.kubernetes.io/last-applied-configuration": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        }
    },
    "spec": {
        "template": {
            "spec": {
                "$setElementOrder/containers": [{
                    "name": "app"
                }],
                "containers": [{
                    "$setElementOrder/env": [{
                        "name": "OLD_VAR_1"
                    }, {
                        "name": "OLD_VAR_2"
                    }, {
                        "name": "OLD_VAR_3"
                    }, {
                        "name": "OLD_VAR_4"
                    }, {
                        "name": "NEW_VAR_1"
                    }, {
                        "name": "NEW_VAR_2"
                    }, {
                        "name": "NEW_VAR_3"
                    }],
                    "dnsPolicy": "ClusterFirst",
                    "env": [{
                        "name": "OLD_VAR_4",
                        "value": false
                    }, {
                        "name": "NEW_VAR_1",
                        "value": 10
                    }, {
                        "name": "NEW_VAR_2",
                        "value": 20
                    }, {
                        "name": "NEW_VAR_3",
                        "value": 6
                    }],
                    "name": "app",
                    "restartPolicy": "Always",
                    "terminationGracePeriodSeconds": 300
                }]
            }
        }
    }
}

OLD_VAR_x are old environment variables; we want to add NEW_VAR_[1-3]. Notice strangely that not all old vars are in env, only OLD_VAR_4, but all new vars are in env.

This also happens when we use oc patch with the same request body. Same error response.

What is wrong?

A workaround is first, deployment, fail, and add new vars in Openshift manually, and deploy in Openshift webconsole on top of the last, failed deployment. It works.


Solution

  • Solved by quoting the var values in the template, like:

    - name: NEW_VAR_X
      value: "${NEW_VAR_VALUE_X}"
    

    No errors ever since.