Skip to content

Commit ef2c556

Browse files
authored
Automatically set or not set resource quota through the cluster (#59)
Set resource if or not depend on k8s quota
1 parent 8e91eb1 commit ef2c556

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

kubectl-node_shell

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ else
140140
fi
141141
fi
142142

143+
# test if resource specification is required
144+
resources_json='"resources": {
145+
"limits": { "cpu": "'${container_cpu}'", "memory": "'${container_memory}'" },
146+
"requests": { "cpu": "'${container_cpu}'", "memory": "'${container_memory}'" }
147+
}'
148+
$kubectl run test --image test --dry-run=server 2>&1 | grep 'failed quota' --quiet || resources_json='"resources": {}'
149+
143150
overrides="$(
144151
cat <<EOT
145152
{
@@ -156,10 +163,7 @@ cat <<EOT
156163
"stdinOnce": true,
157164
"tty": $tty,
158165
"command": $cmd,
159-
"resources": {
160-
"limits": { "cpu": "${container_cpu}", "memory": "${container_memory}" },
161-
"requests": { "cpu": "${container_cpu}", "memory": "${container_memory}" }
162-
},
166+
$resources_json,
163167
"volumeMounts": $volume_mounts
164168
}
165169
],
@@ -172,7 +176,6 @@ cat <<EOT
172176
}
173177
EOT
174178
)"
175-
176179
# Support Kubectl <1.18
177180
m=$(kubectl version --client -o yaml | awk -F'[ :"]+' '$2 == "minor" {print $3+0}')
178181
if [ "$m" -lt 18 ]; then

0 commit comments

Comments
 (0)