invalid json patch when running custom command
part-time-githubber opened this issue · 7 comments
part-time-githubber commented
kubectl node-shell ip-10-240-27-191.eu-west-1.compute.internal -- echo 123
spawning "nsenter-dzp06n" on "ip-10-240-27-191.eu-west-1.compute.internal"
error: Invalid JSON Patch
kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.7", GitCommit:"1dd5338295409edcfff11505e7bb246f0d325d15", GitTreeState:"clean", BuildDate:"2021-01-13T13:23:52Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"18+", GitVersion:"v1.18.9-eks-d1db3c", GitCommit:"d1db3c46e55f95d6a7d3e5578689371318f95ff9", GitTreeState:"clean", BuildDate:"2020-10-20T22:18:07Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
thoughts?
kvaps commented
could you please provide more debug info?
bash -x kubectl-node_shell ip-10-240-27-191.eu-west-1.compute.internal -- echo 123
part-time-githubber commented
bash -x kubectl-node_shell ip-10-240-25-184.eu-west-1.compute.internal -- echo 123
+ set -e
+ kubectl=kubectl
+ generator=
+ node=
+ nodefaultctx=0
+ nodefaultns=0
+ cmd='[ "nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid", "--", '
+ custom=false
+ '[' -p /dev/stdin ']'
+ '[' -p /dev/stdout ']'
+ tty=true
+ '[' 4 -gt 0 ']'
+ key=ip-10-240-25-184.eu-west-1.compute.internal
+ case $key in
+ '[' -z '' ']'
+ node=ip-10-240-25-184.eu-west-1.compute.internal
+ shift
+ '[' 3 -gt 0 ']'
+ key=--
+ case $key in
+ shift
+ break
+ '[' 0 = 1 ']'
++ kubectl config current-context
+ kubectl='kubectl --context=clusteradmin@alpha-euwe1-v1'
+ '[' 0 = 1 ']'
++ kubectl config view --minify --output 'jsonpath={.contexts..namespace}'
+ kubectl='kubectl --context=clusteradmin@alpha-euwe1-v1 --namespace=kube-system'
+ '[' 2 -gt 0 ']'
+ cmd='[ "nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid", "--", "echo", '
+ custom=true
+ shift
+ '[' 1 -gt 0 ']'
+ cmd='[ "nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid", "--", "echo", "123", '
+ custom=true
+ shift
+ '[' 0 -gt 0 ']'
+ '[' true = true ']'
++ echo '[ "nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid", "--", "echo", "123", '
++ awk 1 'RS=, \n'
+ cmd='[ "nsenter"
"--target"
"1"
"--mount"
"--uts"
"--ipc"
"--net"
"--pid"
"--"
"echo"
"123"
]'
+ '[' -z ip-10-240-25-184.eu-west-1.compute.internal ']'
+ image=docker.io/library/alpine
++ env LC_ALL=C tr -dc a-z0-9
++ head -c 6
+ pod=nsenter-exwvp0
+ kubectl get node ip-10-240-25-184.eu-west-1.compute.internal
++ cat
+ overrides='{
"spec": {
"nodeName": "ip-10-240-25-184.eu-west-1.compute.internal",
"hostPID": true,
"hostNetwork": true,
"containers": [
{
"securityContext": {
"privileged": true
},
"image": "docker.io/library/alpine",
"name": "nsenter",
"stdin": true,
"stdinOnce": true,
"tty": true,
"command": [ "nsenter"
"--target"
"1"
"--mount"
"--uts"
"--ipc"
"--net"
"--pid"
"--"
"echo"
"123"
]
}
],
"tolerations": [
{
"key": "CriticalAddonsOnly",
"operator": "Exists"
},
{
"effect": "NoExecute",
"operator": "Exists"
}
]
}
}'
++ kubectl version --client -o yaml
++ awk '-F[ :"]+' '$2 == "minor" {print $3+0}'
+ m=19
+ '[' 19 -lt 18 ']'
+ trap 'EC=$?; kubectl --context=clusteradmin@alpha-euwe1-v1 --namespace=kube-system delete pod --wait=false nsenter-exwvp0 2>/dev/null || true; exit $EC' EXIT INT TERM
+ echo 'spawning "nsenter-exwvp0" on "ip-10-240-25-184.eu-west-1.compute.internal"'
spawning "nsenter-exwvp0" on "ip-10-240-25-184.eu-west-1.compute.internal"
+ kubectl --context=clusteradmin@alpha-euwe1-v1 --namespace=kube-system run --image docker.io/library/alpine --restart=Never '--overrides={
"spec": {
"nodeName": "ip-10-240-25-184.eu-west-1.compute.internal",
"hostPID": true,
"hostNetwork": true,
"containers": [
{
"securityContext": {
"privileged": true
},
"image": "docker.io/library/alpine",
"name": "nsenter",
"stdin": true,
"stdinOnce": true,
"tty": true,
"command": [ "nsenter"
"--target"
"1"
"--mount"
"--uts"
"--ipc"
"--net"
"--pid"
"--"
"echo"
"123"
]
}
],
"tolerations": [
{
"key": "CriticalAddonsOnly",
"operator": "Exists"
},
{
"effect": "NoExecute",
"operator": "Exists"
}
]
}
}' -ti nsenter-exwvp0
error: Invalid JSON Patch
+ EC=1
+ kubectl --context=clusteradmin@alpha-euwe1-v1 --namespace=kube-system delete pod --wait=false nsenter-exwvp0
+ true
+ exit 1
gecube commented
I believe that the part
"command": [ "nsenter"
"--target"
"1"
"--mount"
"--uts"
"--ipc"
"--net"
"--pid"
"--"
"echo"
"123"
]
must look like:
"command": [ "nsenter",
"--target",
"1",
"--mount",
"--uts",
"--ipc",
"--net",
"--pid",
"--",
"echo",
"123"
]
@kvaps any suggestions?
@pankajmt what is your OS and what particular bash version do you use?
kvaps commented
I guess problem not in bash, but in awk.
This @pankajmt please provide your awk --version
info
According the provided debug info, awk is the one who spoils the output of $cmd
.
I decided to avoid using RS variable at all.
This problem should be fixed in v1.2.4 by aae8212
part-time-githubber commented
Many thanks. Should I be able to get this now?
$ kubectl krew update
Updated the local copy of plugin index.
$ kubectl krew upgrade node-shell
Updated the local copy of plugin index.
Upgrading plugin: node-shell
F0331 05:21:01.111818 48636 root.go:79] failed to upgrade plugin "node-shell": can't upgrade, the newest version is already installed
✘ $ kubectl krew list
PLUGIN VERSION
get-all v1.3.7
krew v0.4.1
neat v2.0.2
node-shell v1.2.3
kvaps commented
Ah, I forgot to update default krew repo. It should be available after merge of this PR
kubernetes-sigs/krew-index#1159
part-time-githubber commented
awesome. works now. thanks.