Skip to content

Commit

Permalink
Adding option to add limits and requests to debug pods (#21)
Browse files Browse the repository at this point in the history
* adding limits and requests
* add description for requests and limits
  • Loading branch information
lalitmsft authored Nov 29, 2023
1 parent a92bfd1 commit b2e7b09
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion kubectl-windows-debug
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ case $key in
echo "options:"
echo "-h, --help Show brief help"
echo "-i, --image use custom image"
echo "-r, --requests set resource requests for the debug container (e.g., CPU and memory)"
echo "-l, --limits set resource limit for the debug container (e.g., maximum CPU and memory)"
exit 0
;;
-i | --image)
image="$2"
shift # past argument
shift # past value
;;
-r|--requests)
requests="$2"
shift # past argument
shift # past value
;;
-l|--limits)
limits="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1")
shift # past argument
Expand All @@ -35,13 +47,39 @@ nodename="$1"

echo "Running on node '$nodename' with image '$image'"

echo "Running with requests '$requests' and limits '$limits'"

if [[ -n "${requests}" ]]; then
request_json=$(echo $requests | awk 'BEGIN{FS="[=,]"}{printf "{\"%s\":\"%s\",\"%s\":\"%s\"}", $1, $2, $3, $4}')
else
request_json="{}"
fi

if [[ -n "${limits}" ]]; then
limit_json=$(echo $limits | awk 'BEGIN{FS="[=,]"}{printf "{\"%s\":\"%s\",\"%s\":\"%s\"}", $1, $2, $3, $4}')
else
limit_json="{}"
fi

# sometime ns default is empty from this command so default if it is
namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}')
if [ -z "$namespace" ]; then namespace="default"; fi;

podname=windows-debug-${RANDOM}

overrides=$(cat <<-JSON
{
"spec": {
"containers": [
{
"name": "$podname",
"image": "$image",
"resources": {
"requests": $request_json,
"limits": $limit_json
}
}
],
"nodeName": "$nodename",
"nodeSelector": {
"kubernetes.io/os": "windows"
Expand All @@ -58,9 +96,10 @@ overrides=$(cat <<-JSON
JSON
)

kubectl run windows-debug-${RANDOM} \
kubectl run $podname \
-it --rm -n $namespace --image $image \
--image-pull-policy=Always \
--restart=Never --overrides "$overrides" \
--override-type=strategic \
--pod-running-timeout=15m0s \
--command -- powershell

0 comments on commit b2e7b09

Please sign in to comment.