Skip to content

Add the ability to change the image using --image #66

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

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions kubectl-node_shell
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ volume_mounts="[]"
x_mode=0
labels="${KUBECTL_NODE_SHELL_LABELS}"
pod_running_timeout="${KUBECTL_NODE_SHELL_POD_RUNNING_TIMEOUT:-1m}"
custom_image=""

if [ -t 0 ]; then
tty=true
Expand Down Expand Up @@ -65,6 +66,11 @@ while [ $# -gt 0 ]; do
volume_mounts='[{"mountPath":"/host","name":"host-root"}]'
shift
;;
--image)
custom_image="$2"
shift
shift
;;
--)
shift
break
Expand Down Expand Up @@ -97,15 +103,17 @@ os="$($kubectl get node $node -o jsonpath="{.metadata.labels.kubernetes\.io/os}"

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

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