garethr / garethr-kubernetes

Puppet types and provider for managing Pods, ReplicationControllers, Services and more in Kubernetes
http://garethr.github.io/garethr-kubernetes
Apache License 2.0
28 stars 28 forks source link

Value that is a number generates malformed json #14

Open ghost opened 8 years ago

ghost commented 8 years ago

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.

ingshtrom commented 7 years ago

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!

masterzen commented 6 years ago

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.

teintuc commented 6 years ago

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

maksimu commented 6 years ago

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