TsuyoshiUshio / KubernetesTask

Kubernetes Task for Visual Studio Team Services
34 stars 14 forks source link

error: unable to parse "\"$(cat": yaml" #36

Open Fabinout opened 6 years ago

Fabinout commented 6 years ago

when I use basic commnad kubectl patch, I have this parsing error .

subcommand : patch
arguments : deploy/poc-ci-deployment --patch "$(cat patch.json)" -v=8

2018-05-07T14:59:50.6298360Z ##[debug]exec tool: .vstsbin/kubectl.v1.8.4 2018-05-07T14:59:50.6720260Z ##[debug]arguments: 2018-05-07T14:59:50.7136380Z ##[debug] patch 2018-05-07T14:59:50.8420900Z ##[debug] deploy/poc-ci-deployment 2018-05-07T14:59:50.8831890Z ##[debug] --patch 2018-05-07T14:59:50.9222310Z ##[debug] "$(cat 2018-05-07T14:59:50.9611450Z ##[debug] patch.json)" 2018-05-07T14:59:51.0000820Z ##[debug] -v=8 2018-05-07T14:59:51.0396980Z ##[debug] --kubeconfig 2018-05-07T14:59:51.0812400Z ##[debug] ./kubeconfig 2018-05-07T14:59:51.1082100Z [command] .vstsbin/kubectl.v1.8.4 patch deploy/poc-ci-deployment --patch "$(cat patch.json)" -v=8 --kubeconfig ./kubeconfig 2018-05-07T14:59:51.1348160Z I0507 14:59:47.858994 126502 loader.go:357] Config loaded from file ./kubeconfig 2018-05-07T14:59:51.1607420Z F0507 14:59:47.859132 126502 helpers.go:120] error: unable to parse "\"$(cat": yaml: found unexpected end of stream

It works on Shell though

GimmeDaKitty commented 5 years ago

I have the same issue. I was trying to patch the hostaliases for a deployment. I followed the documentation and provided a valid yaml but got the same error "found unexpected end of stream" The only way to make patching work was to use a json string, like this: kubectl patch deployment mydeployment --patch "{\"spec\":{\"template\":{\"spec\":{\"hostAliases\":[{\"ip\":\"XX.XX.XX.XX\",\"hostnames\":[\"myhostname\"]}]}}}}"

I had to google and try for hours, getting all kind of parsing errors. Finally this post put me on the right path:

If you get the error The specified patch need to be a valid JSON. when you run the above command, you need to modify the above command depending on your operating system, your shell environment and its interpolation behavior.

I am running kubernetes on windows so I looked at the command prompt part:

If you use Command Prompt, you might need to use the following: minishift.exe openshift config set --patch "{\"corsAllowedOrigins\": [\".*\"]}"

So in my case to make it work I did: 1) Used double quotes instead of single quotes for the patch string 2) I escaped all the double quotes inside the patch string from " to \"

On hindsight this is quite obvious if you are using cmd but I do not think this is properly documented in the kubectl patch page. Or else, the option to patch using a valid yaml file should work. Hope this helps anybody