Skip to content

Commit b2e7b09

Browse files
authored
Adding option to add limits and requests to debug pods (#21)
* adding limits and requests * add description for requests and limits
1 parent a92bfd1 commit b2e7b09

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

kubectl-windows-debug

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ case $key in
1717
echo "options:"
1818
echo "-h, --help Show brief help"
1919
echo "-i, --image use custom image"
20+
echo "-r, --requests set resource requests for the debug container (e.g., CPU and memory)"
21+
echo "-l, --limits set resource limit for the debug container (e.g., maximum CPU and memory)"
2022
exit 0
2123
;;
2224
-i | --image)
2325
image="$2"
2426
shift # past argument
2527
shift # past value
2628
;;
29+
-r|--requests)
30+
requests="$2"
31+
shift # past argument
32+
shift # past value
33+
;;
34+
-l|--limits)
35+
limits="$2"
36+
shift # past argument
37+
shift # past value
38+
;;
2739
*) # unknown option
2840
POSITIONAL+=("$1")
2941
shift # past argument
@@ -35,13 +47,39 @@ nodename="$1"
3547

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

50+
echo "Running with requests '$requests' and limits '$limits'"
51+
52+
if [[ -n "${requests}" ]]; then
53+
request_json=$(echo $requests | awk 'BEGIN{FS="[=,]"}{printf "{\"%s\":\"%s\",\"%s\":\"%s\"}", $1, $2, $3, $4}')
54+
else
55+
request_json="{}"
56+
fi
57+
58+
if [[ -n "${limits}" ]]; then
59+
limit_json=$(echo $limits | awk 'BEGIN{FS="[=,]"}{printf "{\"%s\":\"%s\",\"%s\":\"%s\"}", $1, $2, $3, $4}')
60+
else
61+
limit_json="{}"
62+
fi
63+
3864
# sometime ns default is empty from this command so default if it is
3965
namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}')
4066
if [ -z "$namespace" ]; then namespace="default"; fi;
4167

68+
podname=windows-debug-${RANDOM}
69+
4270
overrides=$(cat <<-JSON
4371
{
4472
"spec": {
73+
"containers": [
74+
{
75+
"name": "$podname",
76+
"image": "$image",
77+
"resources": {
78+
"requests": $request_json,
79+
"limits": $limit_json
80+
}
81+
}
82+
],
4583
"nodeName": "$nodename",
4684
"nodeSelector": {
4785
"kubernetes.io/os": "windows"
@@ -58,9 +96,10 @@ overrides=$(cat <<-JSON
5896
JSON
5997
)
6098

61-
kubectl run windows-debug-${RANDOM} \
99+
kubectl run $podname \
62100
-it --rm -n $namespace --image $image \
63101
--image-pull-policy=Always \
64102
--restart=Never --overrides "$overrides" \
103+
--override-type=strategic \
65104
--pod-running-timeout=15m0s \
66105
--command -- powershell

0 commit comments

Comments
 (0)