Skip to content

Commit 65d2851

Browse files
add custom_image (#66)
Co-authored-by: Lior Franko <[email protected]>
1 parent b226162 commit 65d2851

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

kubectl-node_shell

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ volume_mounts="[]"
1414
x_mode=0
1515
labels="${KUBECTL_NODE_SHELL_LABELS}"
1616
pod_running_timeout="${KUBECTL_NODE_SHELL_POD_RUNNING_TIMEOUT:-1m}"
17+
custom_image=""
1718

1819
if [ -t 0 ]; then
1920
tty=true
@@ -65,6 +66,11 @@ while [ $# -gt 0 ]; do
6566
volume_mounts='[{"mountPath":"/host","name":"host-root"}]'
6667
shift
6768
;;
69+
--image)
70+
custom_image="$2"
71+
shift
72+
shift
73+
;;
6874
--)
6975
shift
7076
break
@@ -97,15 +103,17 @@ os="$($kubectl get node $node -o jsonpath="{.metadata.labels.kubernetes\.io/os}"
97103

98104
# Set pod configuration per operating system
99105
if [ "$os" = "windows" ]; then
100-
image="${KUBECTL_NODE_SHELL_IMAGE_WINDOWS:-mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0}"
106+
default_image="mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0"
107+
image="${custom_image:-${KUBECTL_NODE_SHELL_IMAGE_WINDOWS:-$default_image}}"
101108
name="pwsh"
102109
pod="${name}-$(env LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 6)"
103110
cmd_start='"cmd.exe", "/c", "powershell.exe", "-nol"'
104111
cmd_arg_prefix=', "-Command"'
105112
cmd_default=''
106113
security_context='{"privileged":true,"windowsOptions":{"hostProcess":true,"runAsUserName":"NT AUTHORITY\\SYSTEM"}}'
107114
else # If the OS isn't windows, assume linux
108-
image="${KUBECTL_NODE_SHELL_IMAGE:-docker.io/library/alpine}"
115+
default_image="docker.io/library/alpine"
116+
image="${custom_image:-${KUBECTL_NODE_SHELL_IMAGE:-$default_image}}"
109117
name="nsenter"
110118
pod="${name}-$(env LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 6)"
111119
cmd_start='"nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid"'
@@ -183,4 +191,4 @@ fi
183191
trap "EC=\$?; $kubectl delete pod --wait=false $pod >&2 || true; exit \$EC" EXIT INT TERM
184192

185193
echo "spawning \"$pod\" on \"$node\"" >&2
186-
$kubectl run --image "$image" --restart=Never --overrides="$overrides" --labels="$labels" --pod-running-timeout="$pod_running_timeout" $([ "$tty" = true ] && echo -t) -i "$pod" $generator
194+
$kubectl run --image "$image" --restart=Never --overrides="$overrides" --labels="$labels" --pod-running-timeout="$pod_running_timeout" $([ "$tty" = true ] && echo -t) -i "$pod" $generator

0 commit comments

Comments
 (0)