Skip to content

Commit da5cdcd

Browse files
authored
Add flags for netns attach (#68)
* Add flags for netns attach * Update kubectl-node_shell
1 parent 3959c0f commit da5cdcd

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ kubectl node-shell <node> --image <image>
4141
# Use X-mode (mount /host, and do not enter host namespace)
4242
kubectl node-shell -x <node>
4343

44+
# Skip specific namespace types to enter, choose any of ipc, mount, pid, net, uts
45+
kubectl node-shell <node> --no-ipc
46+
4447
# Execute custom command
4548
kubectl node-shell <node> -- echo 123
4649

kubectl-node_shell

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ x_mode=0
1515
labels="${KUBECTL_NODE_SHELL_LABELS}"
1616
pod_running_timeout="${KUBECTL_NODE_SHELL_POD_RUNNING_TIMEOUT:-1m}"
1717
custom_image=""
18+
use_ipc=true
19+
use_mount=true
20+
use_pid=true
21+
use_net=true
22+
use_uts=true
1823

1924
if [ -t 0 ]; then
2025
tty=true
@@ -71,6 +76,26 @@ while [ $# -gt 0 ]; do
7176
shift
7277
shift
7378
;;
79+
--no-ipc)
80+
use_ipc=false
81+
shift
82+
;;
83+
--no-mount)
84+
use_mount=false
85+
shift
86+
;;
87+
--no-pid)
88+
use_pid=false
89+
shift
90+
;;
91+
--no-net)
92+
use_net=false
93+
shift
94+
;;
95+
--no-uts)
96+
use_uts=false
97+
shift
98+
;;
7499
--)
75100
shift
76101
break
@@ -116,7 +141,24 @@ else # If the OS isn't windows, assume linux
116141
image="${custom_image:-${KUBECTL_NODE_SHELL_IMAGE:-$default_image}}"
117142
name="nsenter"
118143
pod="${name}-$(env LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 6)"
119-
cmd_start='"nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid"'
144+
cmd_start='"nsenter", "--target", "1"'
145+
# , "--mount", "--uts", "--ipc", "--net", "--pid"
146+
if [ "$use_mount" = true ]; then
147+
cmd_start="${cmd_start}, \"--mount\""
148+
fi
149+
if [ "$use_uts" = true ]; then
150+
cmd_start="${cmd_start}, \"--uts\""
151+
fi
152+
if [ "$use_ipc" = true ]; then
153+
cmd_start="${cmd_start}, \"--ipc\""
154+
fi
155+
if [ "$use_net" = true ]; then
156+
cmd_start="${cmd_start}, \"--net\""
157+
fi
158+
if [ "$use_pid" = true ]; then
159+
cmd_start="${cmd_start}, \"--pid\""
160+
fi
161+
120162
cmd_arg_prefix=', "--"'
121163
cmd_default=', "bash", "-l"'
122164
security_context='{"privileged":true}'

0 commit comments

Comments
 (0)