Skip to content

old-bash-support #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

old-bash-support #32

wants to merge 1 commit into from

Conversation

joesuf4
Copy link
Contributor

@joesuf4 joesuf4 commented Jul 7, 2021

fixes #29

@joesuf4 joesuf4 force-pushed the little-sed-patch branch 2 times, most recently from 8f0c35d to 7c3a9b1 Compare July 7, 2021 02:59
@kvaps
Copy link
Owner

kvaps commented Jul 7, 2021

@joesuf4, thanks for your PR!
The flowing command is not working to me:

./kubectl-node_shell $node -- sh -c "

echo \"ggg\""
debug output
+ set -e
+ kubectl=kubectl
+ generator=
+ node=
+ nodefaultctx=0
+ nodefaultns=0
+ cmd=(nsenter --target 1 --mount --uts --ipc --net --pid --)
+ custom=false
+ '[' -t 0 ']'
+ tty=true
+ '[' 5 -gt 0 ']'
+ key=m1c4
+ case $key in
+ '[' -z '' ']'
+ node=m1c4
+ shift
+ '[' 4 -gt 0 ']'
+ key=--
+ case $key in
+ shift
+ break
+ '[' 0 = 1 ']'
++ kubectl config current-context
+ kubectl='kubectl --context=stage-opennebula'
+ '[' 0 = 1 ']'
++ kubectl --context=stage-opennebula config view --minify --output 'jsonpath={.contexts..namespace}'
+ kubectl='kubectl --context=stage-opennebula --namespace=opennebula'
+ '[' 3 -gt 0 ']'
+ cmd+=("${@//
/\\n}")
+ cmd=("${cmd[@]//\'/\"}")
++ echo -e '['\''nsenter'\'', '\''' '--target'\'', '\''' '1'\'', '\''' '--mount'\'', '\''' '--uts'\'', '\''' '--ipc'\'', '\''' '--net'\'', '\''' '--pid'\'', '\''' '--'\'', '\''' 'sh'\'', '\''' '-c'\'', '\''' '\n\necho "ggg"'\'', '\'''\'']'
++ sed -e 's/'\'' /'\''/g' -e 's/, '\'''\'']$/]/' -Ee 's/(["\\])/\\\1/g' -e 's/\\\\n/\\n/g'
++ tr \' '"'
+ entrypoint='["nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid", "--", "sh", "-c", "

echo "ggg""]'

  • '[' -z m1c4 ']'
  • image=docker.io/library/alpine
    ++ env LC_ALL=C tr -dc a-z0-9
    ++ head -c 6
  • pod=nsenter-4n8vr2
  • kubectl --context=stage-opennebula --namespace=opennebula get node m1c4
    ++ cat
  • overrides='{
    "spec": {
    "nodeName": "m1c4",
    "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", "--", "sh", "-c", "

echo "ggg""]
}
],
"tolerations": [
{
"key": "CriticalAddonsOnly",
"operator": "Exists"
},
{
"effect": "NoExecute",
"operator": "Exists"
}
]
}
}'
++ kubectl version --client -o yaml
++ awk '-F[ :"]+' '$2 == "minor" {print $3+0}'

  • m=21
  • '[' 21 -lt 18 ']'
  • trap 'EC=$?; kubectl --context=stage-opennebula --namespace=opennebula delete pod --wait=false nsenter-4n8vr2 >&2 || true; exit $EC' EXIT INT TERM
  • echo 'spawning "nsenter-4n8vr2" on "m1c4"'
    spawning "nsenter-4n8vr2" on "m1c4"
    ++ '[' -t 0 ']'
    ++ echo -t
  • kubectl --context=stage-opennebula --namespace=opennebula run --image docker.io/library/alpine --restart=Never '--overrides={
    "spec": {
    "nodeName": "m1c4",
    "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", "--", "sh", "-c", "

echo "ggg""]
}
],
"tolerations": [
{
"key": "CriticalAddonsOnly",
"operator": "Exists"
},
{
"effect": "NoExecute",
"operator": "Exists"
}
]
}
}' -t -i nsenter-4n8vr2
error: Invalid JSON Patch

  • EC=1
  • kubectl --context=stage-opennebula --namespace=opennebula delete pod --wait=false nsenter-4n8vr2
    Error from server (NotFound): pods "nsenter-4n8vr2" not found
  • true
  • exit 1
version information
$ bash --version
GNU bash, version 5.1.8(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ sed --version
sed (GNU sed) 4.8
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later https://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
Paolo Bonzini, Jim Meyering, and Assaf Gordon.

This sed program was built without SELinux support.

GNU sed home page: https://www.gnu.org/software/sed/.
General help using GNU software: https://www.gnu.org/gethelp/.
E-mail bug reports to: [email protected].

@joesuf4 joesuf4 force-pushed the little-sed-patch branch 2 times, most recently from baa7c5f to 8fc5e1e Compare July 7, 2021 22:37
@joesuf4
Copy link
Contributor Author

joesuf4 commented Jul 8, 2021 via email

@joesuf4 joesuf4 force-pushed the little-sed-patch branch 2 times, most recently from 9ad6c11 to 0289bb8 Compare July 8, 2021 14:12
- echo -e
- requires more newline escapes
@kvaps
Copy link
Owner

kvaps commented Jul 8, 2021

Okay, here is also a few amount of tests:

./kubectl-node_shell $node -- sh -c 'echo $(echo "
hello everybody
I'\''m a \"baby seal\""

)'



./kubectl-node_shell $node -- sh -c "

echo \"ggg


ttt\""



./kubectl-node_shell $node -- sh -c 'echo $(echo "
hello everybody
I'\''m a \"baby seal

really really

\""
)'

@kvaps
Copy link
Owner

kvaps commented Jul 8, 2021

Actually I wrote these tests for myself you can still implement them. Although I still not sure about the advantages of sed+bash over pure shell+awk version. Awk and bourne shell is the same almost everywhere. Thus if you can't convince me, I'm going to merge version from #31
FYI

@joesuf4
Copy link
Contributor Author

joesuf4 commented Jul 8, 2021 via email

@joesuf4
Copy link
Contributor Author

joesuf4 commented Jul 8, 2021 via email

@joesuf4
Copy link
Contributor Author

joesuf4 commented Jul 8, 2021 via email

@kvaps
Copy link
Owner

kvaps commented Jul 8, 2021

@joesuf4 thanks for explanation.

I found even more elegant way with awk, I merged #31 and going to close this PR.
Thanks for your contribution!

@kvaps kvaps closed this Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error from server (NotFound): pods "nsenter-qylbtm" not found
2 participants