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

add bash script to toggle cluster status #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
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 "\r %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}"