-
-
Save MichaelSp/413dbed33ac365a0f724b43893c97b78 to your computer and use it in GitHub Desktop.
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
#!/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