-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: zsh and refactor scripts (#159)
* fix: zsh to be the default shell by updating how the vscode user is created fix: scripts so that they are copied to /usr/bin and accessible by all shells with a proper PATH major: remove run-gha and fetch repos shortct * feat: update python version to 3.11.10
- Loading branch information
1 parent
6c885da
commit aefc8d8
Showing
9 changed files
with
146 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
130 changes: 66 additions & 64 deletions
130
.devcontainer/tools/cordon-drain-nodes-older-than-minutes.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,76 @@ | ||
#!/bin/bash | ||
|
||
cordon-drain-nodes-older-than-minutes() { | ||
threshold_minutes="" | ||
|
||
while [[ $# -gt 0 ]]; do | ||
key="$1" | ||
case $key in | ||
(-m|--threshold-minutes) | ||
threshold_minutes="$2" | ||
shift | ||
shift | ||
;; | ||
(--help) | ||
echo "Usage: cordon-drain-nodes-older-than-minutes [options]" | ||
echo "" | ||
echo "Options:" | ||
echo " -m, --threshold-minutes VALUE Target nodes older than this many minutes." | ||
echo " --help Show this help message and exit" | ||
return | ||
;; | ||
(*) | ||
echo "Unknown option: $key" | ||
echo "Run 'cordon-drain-nodes-older-than-minutes --help' for usage information." | ||
return | ||
;; | ||
esac | ||
done | ||
threshold_minutes="" | ||
|
||
while [[ $# -gt 0 ]]; do | ||
key="$1" | ||
case $key in | ||
(-m|--threshold-minutes) | ||
threshold_minutes="$2" | ||
shift | ||
shift | ||
;; | ||
(--help) | ||
echo "Usage: cordon-drain-nodes-older-than-minutes [options]" | ||
echo "" | ||
echo "Options:" | ||
echo " -m, --threshold-minutes VALUE Target nodes older than this many minutes." | ||
echo " --help Show this help message and exit" | ||
exit 0 | ||
;; | ||
(*) | ||
echo "Unknown option: $key" | ||
echo "Run 'cordon-drain-nodes-older-than-minutes --help' for usage information." | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
CURRENT_DATE=$(date +%s) | ||
if [ -z "$threshold_minutes" ]; then | ||
echo "Error: --threshold-minutes is required." | ||
echo "Run 'cordon-drain-nodes-older-than-minutes --help' for usage information." | ||
exit 1 | ||
fi | ||
|
||
NODES=$(kubectl get nodes -o json | jq --arg CURRENT_DATE "$CURRENT_DATE" --arg THRESHOLD_MINUTES "$threshold_minutes" -r ' | ||
.items[] | | ||
select( | ||
.metadata.creationTimestamp | fromdateiso8601 < ($CURRENT_DATE | tonumber) - ($THRESHOLD_MINUTES | tonumber * 60) | ||
) | .metadata.name') | ||
CURRENT_DATE=$(date +%s) | ||
|
||
if [ -z "$NODES" ]; then | ||
echo "No nodes older than $threshold_minutes minutes found." | ||
exit 0 | ||
fi | ||
NODES=$(kubectl get nodes -o json | jq --arg CURRENT_DATE "$CURRENT_DATE" --arg THRESHOLD_MINUTES "$threshold_minutes" -r ' | ||
.items[] | | ||
select( | ||
.metadata.creationTimestamp | fromdateiso8601 < ($CURRENT_DATE | tonumber) - ($THRESHOLD_MINUTES | tonumber * 60) | ||
) | .metadata.name') | ||
|
||
echo "Nodes found older than $threshold_minutes minutes:" | ||
echo "$NODES" | ||
echo "" | ||
if [ -z "$NODES" ]; then | ||
echo "No nodes older than $threshold_minutes minutes found." | ||
exit 0 | ||
fi | ||
|
||
echo -n "Cordon the listed nodes? (y/N) " | ||
read response | ||
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | ||
echo "$NODES" | while IFS= read -r node; do | ||
echo "Cordoning node: $node" | ||
kubectl cordon "$node" | ||
echo "" | ||
done | ||
else | ||
echo "Cordoning skipped. Will not attempt to drain." | ||
return 0 | ||
fi | ||
echo "Nodes found older than $threshold_minutes minutes:" | ||
echo "$NODES" | ||
echo "" | ||
|
||
echo -n "Drain the cordoned nodes? (y/N) " | ||
read response | ||
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | ||
echo "$NODES" | while IFS= read -r node; do | ||
echo "Draining node: $node" | ||
kubectl drain "$node" --ignore-daemonsets --delete-emptydir-data > "drain-${node}.log" 2>&1 & | ||
done | ||
wait | ||
echo "All nodes drained." | ||
else | ||
echo "Draining skipped." | ||
fi | ||
echo -n "Cordon the listed nodes? (y/N) " | ||
read -r response | ||
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | ||
echo "$NODES" | while IFS= read -r node; do | ||
echo "Cordoning node: $node" | ||
kubectl cordon "$node" | ||
echo "" | ||
done | ||
else | ||
echo "Cordoning skipped. Will not attempt to drain." | ||
exit 0 | ||
fi | ||
|
||
} | ||
echo -n "Drain the cordoned nodes? (y/N) " | ||
read -r response | ||
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | ||
echo "$NODES" | while IFS= read -r node; do | ||
echo "Draining node: $node" | ||
kubectl drain "$node" --ignore-daemonsets --delete-emptydir-data > "drain-${node}.log" 2>&1 & | ||
done | ||
wait | ||
echo "All nodes drained." | ||
else | ||
echo "Draining skipped." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
create-ghcr-regcred() { | ||
gh_username="" | ||
gh_token="" | ||
#!/bin/bash | ||
|
||
# Parse flags | ||
while [[ $# -gt 0 ]]; do | ||
key="$1" | ||
case $key in | ||
(-u|--github-username) | ||
gh_username="$2" | ||
shift | ||
shift | ||
;; | ||
(-t|--github-token) | ||
gh_token="$2" | ||
shift | ||
shift | ||
;; | ||
(--help) | ||
echo "Usage: create-ghcr-regcred [options]" | ||
echo "" | ||
echo "Options:" | ||
echo " -u, --github-username VALUE The github username associated with the token" | ||
echo " -t, --github-token VALUE The github token that enables pull access to ghcr" | ||
echo " --help Show this help message and exit" | ||
return | ||
;; | ||
(*) | ||
echo "Unknown option: $key" | ||
echo "Run 'create-ghcr-regcred --help' for usage information." | ||
return | ||
;; | ||
esac | ||
done | ||
gh_username="" | ||
gh_token="" | ||
|
||
# Check if version arguments were provided | ||
if [[ -z $gh_username || -z $gh_token ]]; then | ||
echo "Both arguments are required." | ||
echo "Run 'create-ghcr-regcred --help' for usage information." | ||
return | ||
fi | ||
# Parse flags | ||
while [[ $# -gt 0 ]]; do | ||
key="$1" | ||
case $key in | ||
(-u|--github-username) | ||
gh_username="$2" | ||
shift | ||
shift | ||
;; | ||
(-t|--github-token) | ||
gh_token="$2" | ||
shift | ||
shift | ||
;; | ||
(--help) | ||
echo "Usage: create-ghcr-regcred [options]" | ||
echo "" | ||
echo "Options:" | ||
echo " -u, --github-username VALUE The github username associated with the token" | ||
echo " -t, --github-token VALUE The github token that enables pull access to ghcr" | ||
echo " --help Show this help message and exit" | ||
exit 0 | ||
;; | ||
(*) | ||
echo "Unknown option: $key" | ||
echo "Run 'create-ghcr-regcred --help' for usage information." | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
set -e | ||
b64_enc_regcred=$(echo -n "$gh_username:$gh_token" | base64) | ||
# Check if required arguments were provided | ||
if [[ -z $gh_username || -z $gh_token ]]; then | ||
echo "Error: Both --github-username and --github-token are required." | ||
echo "Run 'create-ghcr-regcred --help' for usage information." | ||
exit 1 | ||
fi | ||
|
||
echo "{\"auths\":{\"ghcr.io\":{\"auth\":\"$b64_enc_regcred\"}}}" | ||
} | ||
set -e | ||
b64_enc_regcred=$(echo -n "$gh_username:$gh_token" | base64) | ||
|
||
echo "{\"auths\":{\"ghcr.io\":{\"auth\":\"$b64_enc_regcred\"}}}" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
yolo() { | ||
# Always unset GITHUB_TOKEN | ||
unset GITHUB_TOKEN | ||
#!/bin/bash | ||
|
||
# If the file doesn't exist or 'gh auth status' returns an exit code of 1 | ||
if [[ ! -f /home/vscode/.config/gh/hosts.yml ]] || ! gh auth status; then | ||
# If the file doesn't exist or 'gh auth status' fails, then proceed with the rest of the script | ||
# Always unset GITHUB_TOKEN | ||
unset GITHUB_TOKEN | ||
|
||
# Run the gh auth login command | ||
yes Y | gh auth login -h github.com -p https -w -s repo,workflow,admin:org,write:packages,user,gist,notifications,admin:repo_hook,admin:public_key,admin:enterprise,audit_log,codespace,project,admin:gpg_key,admin:ssh_signing_key | ||
# If the file doesn't exist or 'gh auth status' returns an exit code of 1 | ||
if [[ ! -f /home/vscode/.config/gh/hosts.yml ]] || ! gh auth status &>/dev/null; then | ||
# If the file doesn't exist or 'gh auth status' fails, then proceed with the rest of the script | ||
|
||
echo "Set up git with gh auth" | ||
gh auth setup-git | ||
# Run the gh auth login command | ||
yes Y | gh auth login -h github.com -p https -w -s repo,workflow,admin:org,write:packages,user,gist,notifications,admin:repo_hook,admin:public_key,admin:enterprise,audit_log,codespace,project,admin:gpg_key,admin:ssh_signing_key | ||
|
||
# Configure git config | ||
git_email=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user/emails | jq '.[] | select(.primary == true) | .email' -r) | ||
git_name=$(gh api user | jq '.name' -r) | ||
git config --global user.email "${git_email}" | ||
git config --global user.name "${git_name}" | ||
git config --global core.autocrlf input | ||
fi | ||
} | ||
echo "Set up git with gh auth" | ||
gh auth setup-git | ||
|
||
# Configure git config | ||
git_email=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user/emails | jq '.[] | select(.primary == true) | .email' -r) | ||
git_name=$(gh api user | jq '.name' -r) | ||
git config --global user.email "${git_email}" | ||
git config --global user.name "${git_name}" | ||
git config --global core.autocrlf input | ||
else | ||
echo "GitHub authentication is already set up." | ||
gh auth status | ||
fi |