From a457259302b58b865e0dc7e2891d559e52242c1b Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Thu, 31 Jul 2025 11:20:21 -0700 Subject: [PATCH] wait for running GKE operations to finish before deleting a cluster --- pipelines/shared-tasks/remove-gke-cluster/task.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pipelines/shared-tasks/remove-gke-cluster/task.sh b/pipelines/shared-tasks/remove-gke-cluster/task.sh index d58bb8d05..47259f96e 100755 --- a/pipelines/shared-tasks/remove-gke-cluster/task.sh +++ b/pipelines/shared-tasks/remove-gke-cluster/task.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2020-2024 the Pinniped contributors. All Rights Reserved. +# Copyright 2020-2025 the Pinniped contributors. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 set -euo pipefail @@ -18,6 +18,18 @@ if [[ -z $zone || "$CLUSTER_NAME" != *"-zone-"* ]]; then exit 1 fi +for i in $(seq 1 10); do + echo "Checking $CLUSTER_NAME for ongoing operations (iteration $i)...." + running_ops=$(gcloud container operations list --filter="targetLink:$CLUSTER_NAME AND status != done" --project "$GCP_PROJECT" --zone "$zone" --format yaml) + if [[ -z "$running_ops" ]]; then + break + fi + echo "Found a running cluster operation:" + echo "$running_ops" + # Give some time for the operation to finsh before checking again. + sleep 30 +done + echo "Removing $CLUSTER_NAME..." gcloud auth activate-service-account "$GCP_SERVICE_ACCOUNT" --key-file <(echo "$GCP_JSON_KEY") --project "$GCP_PROJECT" gcloud container clusters delete "$CLUSTER_NAME" --zone "$zone" --quiet