Skip to content

Instantly share code, notes, and snippets.

@MichaelSp
Forked from nobiit/remove_runner_offline.sh
Created July 27, 2022 14:26
Show Gist options
  • Save MichaelSp/413dbed33ac365a0f724b43893c97b78 to your computer and use it in GitHub Desktop.
Save MichaelSp/413dbed33ac365a0f724b43893c97b78 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
github_token=$(kubectl get -n runner-system secrets controller-manager -o json | jq -r .data.github_token | base64 -d)
function list_organization {
kubectl get runner -A -o json | jq -r .items[].spec.organization
kubectl get runnerset -A -o json | jq -r .items[].spec.organization
}
for item in $(list_organization | uniq); do
page=0
while true; do
page=$(expr ${page} + 1)
runners=$(curl -s -u token:${github_token} "https://api.github.com/orgs/${item}/actions/runners?page=${page}")
if [ $(echo ${runners} | jq -r '.runners | length') == 0 ]; then
break
fi
for runner in $(echo ${runners} | jq -r '.runners[] | select(.status == "offline") | tojson'); do
echo ${runner} | jq -r .
runner_id=$(echo ${runner} | jq -r .id)
curl -s -u token:${github_token} -X DELETE "https://api.github.com/orgs/${item}/actions/runners/${runner_id}"
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment