garethr-kubernetes icon indicating copy to clipboard operation
garethr-kubernetes copied to clipboard

Value that is a number generates malformed json

Open ghost opened this issue 9 years ago • 4 comments

When specifying a value, e.g. in 'env' block, if it is a number the module generates a malformed json.

Example:

kubernetes_pod { 'puppet-demo': ... spec => { 'containers' => [{ .... 'env' => [ { 'name' => 'MYVAR', 'value' => '1' }, ], }, }

Returns the error code:

Error: Could not set 'present' on ensure: HTTP status code 400, Pod in version "v1" cannot be handled as a Pod: [pos 301]: json: expect char '"' but got char '1' at 23:....myfile.pp Wrapped exception: Pod in version "v1" cannot be handled as a Pod: [pos 301]: json: expect char '"' but got char '1'

Note that changing the 1 to anything else non-numeric works.

ghost avatar May 09 '16 16:05 ghost

I found that the problem I had as passing in env variables as non-strings. I am using YAML, but the same might be the case. I had: image and I changed that to: image

This solved my problem with getting the error: image

I hope this helps you!

ingshtrom avatar May 21 '17 15:05 ingshtrom

We just got this issue, it's coming from the fact that the module automatically converts to integers all strings looking as an integer (see fixnumify).

I think @garethr original idea was to prevent kubernetes errors if you setup for instance a container port to '443' instead of 443.

In any case, env variable value should never be fixnumified.

masterzen avatar Oct 11 '17 15:10 masterzen

I push this PR which should fix the problem. May be not optimal though. Open to suggestions

teintuc avatar Oct 13 '17 14:10 teintuc

https://github.com/garethr/garethr-kubernetes/issues/14#issuecomment-302944595 fixed my issue 👍

maksimu avatar Nov 02 '17 20:11 maksimu