Skip to content
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

Automatically set or not set resource quota through the cluster #59

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Changes from 2 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
20 changes: 15 additions & 5 deletions kubectl-node_shell
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ else
fi
fi

# test if resource specification is required
set +e
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set +e

Copy link
Contributor Author

@pycgo pycgo Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if do not set this,when grep nothting ,the shell will exit ,can you test it in no limit cluster ?
I can not find other way to fix it.

$kubectl run test --image test --dry-run=server 2>&1|grep forbidden --quiet
pycgo marked this conversation as resolved.
Show resolved Hide resolved
if [ $? -eq 0 ];then
resources_json='"resources": {
"limits": { "cpu": "'${container_cpu}'", "memory": "'${container_memory}'" },
"requests": { "cpu": "'${container_cpu}'", "memory": "'${container_memory}'" }
}'
else
resources_json='"resources": {}'

fi
set -e
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set -e


overrides="$(
cat <<EOT
{
Expand All @@ -156,10 +170,7 @@ cat <<EOT
"stdinOnce": true,
"tty": $tty,
"command": $cmd,
"resources": {
"limits": { "cpu": "${container_cpu}", "memory": "${container_memory}" },
"requests": { "cpu": "${container_cpu}", "memory": "${container_memory}" }
},
$resources_json,
"volumeMounts": $volume_mounts
}
],
Expand All @@ -172,7 +183,6 @@ cat <<EOT
}
EOT
)"

# Support Kubectl <1.18
m=$(kubectl version --client -o yaml | awk -F'[ :"]+' '$2 == "minor" {print $3+0}')
if [ "$m" -lt 18 ]; then
Expand Down