Skip to content

Commit

Permalink
add bash script to toggle cluster status
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrifiro committed Mar 15, 2024
1 parent b863404 commit f55f125
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions contrib/toggle_cluster_state_gha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
# Uses the github cli (and jq) to toggle cluster status. Run with no arguments for usage

function usage() {
echo "Usage: $(basename "$0") resume|hibernate <cluster_name>"
}

if [[ $1 == "resume" ]]; then
workflow="resume_cluster.yaml"
elif [[ $1 == "hibernate" ]]; then
workflow="hibernate_cluster.yaml"
else
usage
exit 1
fi

if [[ -z "$2" ]]; then
usage
exit 1
fi

set -euo pipefail

cluster_name="$2"
ocm_account="PROD (console.redhat.com)"

gh workflow run \
--repo red-hat-data-services/Cloud-Cost-Optimization \
-F cluster_name="${cluster_name}" \
-F ocm_account="${ocm_account}" \
"${workflow}"

run_id=""
max_retries=120
until [[ -n $run_id ]]; do
printf " %s | 🟡 Waiting for job to start..." "$(date +%H:%M:%S)"
run_id=$(
gh run list \
--workflow=${workflow} \
--repo red-hat-data-services/Cloud-Cost-Optimization \
--status="in_progress" \
--limit 1 \
--jq '.[0].databaseId' --json databaseId
)
max_retries=$((max_retries - 1))
if [[ ${max_retries} -le 0 ]]; then
printf "\n🔴 Failed to get job. Check on https://github.com/red-hat-data-services/Cloud-Cost-Optimization/actions"
exit 1
fi
sleep 1
done

printf "\n 🟢 Workflow is running"
run_id="$(gh run list \
--workflow=${workflow} \
--repo red-hat-data-services/Cloud-Cost-Optimization \
--limit 1 \
--jq '.[0].databaseId' --json databaseId)"

printf " run_id=%s\n" "${run_id}"

gh run \
--repo red-hat-data-services/Cloud-Cost-Optimization \
watch "${run_id}"

0 comments on commit f55f125

Please sign in to comment.