/kind bug
What happened:
What you expected to happen:
Patch applied to my kubectl run. See proper expected output from Mac OS run below.
How to reproduce it (as minimally and precisely as possible):
kubectl run pfa --image=myimage --overrides='{"apiVersion":"apps/v1beta1","spec":{"template":{"spec":{"imagePullSecrets":[{"name":"myregkey"}]}}}}' --dry-run -o yaml
Anything else we need to know?:
Output on Windows:
error: Invalid JSON Patch
Output on Windows (with -v6 added to the end of the command):
I0810 12:11:06.986876 135292 round_trippers.go:405] GET https://192.168.99.100:8443/apis/apps/v1beta1?timeout=32s 200 OK in 11 milliseconds
I0810 12:11:06.987852 135292 loader.go:359] Config loaded from file C:\Users\paul/.kube/config
F0810 12:11:06.992733 135292 helpers.go:119] error: Invalid JSON Patch
Output on MacOS:
```apiVersion: apps/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
run: pfa
name: pfa
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
run: pfa
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: pfa
spec:
containers:
- image: myimage
imagePullPolicy: Always
name: pfa
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: myregkey
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status: {}
**Environment**:
- Kubernetes version (use `kubectl version`):
Windows Version:
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.2", GitCommit:"bb9ffb1654d4a729bb4cec18ff088eacc153c239", GitTreeState:"clean", BuildDate:"2018-08-07T23:17:28Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:44:10Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Mac OS Version:
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.2", GitCommit:"bb9ffb1654d4a729bb4cec18ff088eacc153c239", GitTreeState:"clean", BuildDate:"2018-08-08T16:31:10Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:44:10Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
```
Cloud provider or hardware configuration:
using minikube 0.28.2 with --vm-driver=virtualbox in both Windows and Mac OS cases.
OS (e.g. from /etc/os-release):
Windows 10 & MacOS
Kernel (e.g. uname -a):
Darwin
Install tools:
minikube and kubernetes-cli installed using brew on MacOS, and using chocolatey on Windows.
/sig cli
/area kubectl
/priority P2
Using " instead of ' around --overrides input working for me in Windows. example:- kubectl run test --image=myimage --overrides="{"apiVersion":"apps/v1beta1","spec":{"template":{"spec":{"imagePullSecrets":[{"name":"myregkey"}]}}}}" --dry-run -o yaml
FWIW replacing ' with " technique didn't work for me.
$kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.7-gke.11", GitCommit:"fa90543563c9cfafca69128ce8cd9ecd5941940f", GitTreeState:"clean", BuildDate:"2018-11-08T20:22:21Z", GoVersion:"go1.9.3b4", Compiler:"gc", Platform:"linux/amd64"}
I'm sharing this having gone through the same battle yesterday with the kubectl run command. If you're running this on Windows using Powershell you'll need to create a variable and assign the JSON (using the ConvertTo-Json routine) first. Then use that variable in your kubectl commands.
From the OP's code:
kubectl run pfa --image=myimage --overrides='{"apiVersion":"apps/v1beta1","spec":{"template":{"spec":{"imagePullSecrets":[{"name":"myregkey"}]}}}}' --dry-run -o yaml
Becomes:
$myjson = '{"apiVersion":"apps/v1beta1","spec":{"template":{"spec":{"imagePullSecrets":[{"name":"myregkey"}]}}}}' | ConvertTo-Json
kubectl run pfa --image=myimage --overrides=$myjson --dry-run -o yaml
Hope that helps! :)
Approach originally found at: https://stackoverflow.com/a/53481499/40593
FWIW replacing
'with"technique didn't work for me.$kubectl version Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"} Server Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.7-gke.11", GitCommit:"fa90543563c9cfafca69128ce8cd9ecd5941940f", GitTreeState:"clean", BuildDate:"2018-11-08T20:22:21Z", GoVersion:"go1.9.3b4", Compiler:"gc", Platform:"linux/amd64"}
In my example I missed escaping " inside --overrides input.
kubectl run test --image=myimage --overrides="{\"apiVersion\":\"apps/v1beta1\",\"spec\":{\"template\":{\"spec\":{\"imagePullSecrets\":[{\"name\":\"myregkey\"}]}}}}" --dry-run -o yaml
'{"apiVersion":"apps/v1beta1","spec":{"template":{"spec":{"imagePullSecrets":[{"name":"myregkey"}]}}}}' | ConvertTo-Json does samething. It gives same output "{\"apiVersion\":\"apps/v1beta1\",\"spec\":{\"template\":{\"spec\":{\"imagePullSecrets\":[{\"name\":\"myregkey\"}]}}}}"
Thanks both. I followed @woodwardmatt 's way and it worked, with a couple of caveats:
\n
'{ "name": "John_Smith" }' # <- works
'{ "name": "John Smith" }' # <- doesn't work
error: Invalid JSON Patch, at least in my local environment.Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close
@fejta-bot: Closing this issue.
In response to this:
Rotten issues close after 30d of inactivity.
Reopen the issue with/reopen.
Mark the issue as fresh with/remove-lifecycle rotten.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
I still had this problem on Windows kubectl v1.15.5; and escaping the inner double-quotes with a \ backslash did not work. Very frustrating. Just for the hell of it, I escaped each inner double-quote with the C# style triple-double-quote, and it worked! Go figure, LOL
--overrides '{ """apiVersion""": """v1""","""spec""":{"""ports""":[{"""port""":2830,"""protocol""":"""TCP""","""targetPort""":2830,"""nodePort""":30031}]}}'
Most helpful comment
I'm sharing this having gone through the same battle yesterday with the kubectl run command. If you're running this on Windows using Powershell you'll need to create a variable and assign the JSON (using the ConvertTo-Json routine) first. Then use that variable in your kubectl commands.
From the OP's code:
kubectl run pfa --image=myimage --overrides='{"apiVersion":"apps/v1beta1","spec":{"template":{"spec":{"imagePullSecrets":[{"name":"myregkey"}]}}}}' --dry-run -o yamlBecomes:
Hope that helps! :)
Approach originally found at: https://stackoverflow.com/a/53481499/40593