From 0debb3c161de085775cf513d07dd327f614893d5 Mon Sep 17 00:00:00 2001 From: Cristiano Veiga Date: Thu, 26 Mar 2026 14:48:39 -0400 Subject: [PATCH] fix(hypershift/gcp): handle missing hosted-cluster-name in deprovision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to GCP-484. When a job is aborted after gke-provision but before hosted-cluster-setup, the deprovision script crashes reading the missing hosted-cluster-name file, leaving GCP projects orphaned. Make hosted-cluster-name optional and skip DNS cleanup when it is absent — no hosted clusters means no DNS records to clean up. Co-Authored-By: Claude Opus 4.6 --- ...hypershift-gcp-gke-deprovision-commands.sh | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/ci-operator/step-registry/hypershift/gcp/gke/deprovision/hypershift-gcp-gke-deprovision-commands.sh b/ci-operator/step-registry/hypershift/gcp/gke/deprovision/hypershift-gcp-gke-deprovision-commands.sh index b122db044c80a..6c36a8754bd7a 100644 --- a/ci-operator/step-registry/hypershift/gcp/gke/deprovision/hypershift-gcp-gke-deprovision-commands.sh +++ b/ci-operator/step-registry/hypershift/gcp/gke/deprovision/hypershift-gcp-gke-deprovision-commands.sh @@ -16,9 +16,17 @@ fi # Load cluster info from provision and hosted-cluster-setup steps CP_PROJECT_ID="$(<"${SHARED_DIR}/control-plane-project-id")" CP_CLUSTER_NAME="$(<"${SHARED_DIR}/control-plane-cluster-name")" -HC_CLUSTER_NAME="$(<"${SHARED_DIR}/hosted-cluster-name")" GCP_REGION="$(<"${SHARED_DIR}/gcp-region")" +# hosted-cluster-name may not exist if job was aborted before hosted-cluster-setup ran +if [[ -f "${SHARED_DIR}/hosted-cluster-name" ]]; then + HC_CLUSTER_NAME="$(<"${SHARED_DIR}/hosted-cluster-name")" +else + HC_CLUSTER_NAME="" + echo "WARNING: hosted-cluster-name not found - hosted cluster setup may not have completed" + echo "Will skip DNS cleanup but still deprovision GKE cluster and projects" +fi + # Hosted Cluster project file path (may not exist if provision failed early) HC_PROJECT_FILE="${SHARED_DIR}/hosted-cluster-project-id" if [[ -f "${HC_PROJECT_FILE}" ]]; then @@ -90,25 +98,29 @@ gcloud projects delete "${CP_PROJECT_ID}" --quiet || true EXTERNAL_DNS_GSA="external-dns@${HYPERSHIFT_GCP_CI_PROJECT}.iam.gserviceaccount.com" # Clean up DNS records from the CI zone (DNS records use the hosted cluster name) -echo "Cleaning up DNS records for hosted cluster ${HC_CLUSTER_NAME}..." -DNS_SUFFIX="in.${HC_CLUSTER_NAME}.${HYPERSHIFT_GCP_CI_DNS_DOMAIN}." -DNS_RECORDS=$(gcloud dns record-sets list \ - --zone="${HYPERSHIFT_GCP_CI_DNS_ZONE}" \ - --project="${HYPERSHIFT_GCP_CI_PROJECT}" \ - --filter="name ~ ${DNS_SUFFIX}" \ - --format="csv[no-heading](name,type)" 2>/dev/null || true) - -if [[ -n "${DNS_RECORDS}" ]]; then - while IFS=, read -r name type; do - [[ -z "${name}" ]] && continue - echo "Deleting DNS record: ${name} ${type}" - gcloud dns record-sets delete "${name}" \ - --type="${type}" \ - --zone="${HYPERSHIFT_GCP_CI_DNS_ZONE}" \ - --project="${HYPERSHIFT_GCP_CI_PROJECT}" --quiet || true - done <<< "${DNS_RECORDS}" +if [[ -n "${HC_CLUSTER_NAME}" ]]; then + echo "Cleaning up DNS records for hosted cluster ${HC_CLUSTER_NAME}..." + DNS_SUFFIX="in.${HC_CLUSTER_NAME}.${HYPERSHIFT_GCP_CI_DNS_DOMAIN}." + DNS_RECORDS=$(gcloud dns record-sets list \ + --zone="${HYPERSHIFT_GCP_CI_DNS_ZONE}" \ + --project="${HYPERSHIFT_GCP_CI_PROJECT}" \ + --filter="name ~ ${DNS_SUFFIX}" \ + --format="csv[no-heading](name,type)" 2>/dev/null || true) + + if [[ -n "${DNS_RECORDS}" ]]; then + while IFS=, read -r name type; do + [[ -z "${name}" ]] && continue + echo "Deleting DNS record: ${name} ${type}" + gcloud dns record-sets delete "${name}" \ + --type="${type}" \ + --zone="${HYPERSHIFT_GCP_CI_DNS_ZONE}" \ + --project="${HYPERSHIFT_GCP_CI_PROJECT}" --quiet || true + done <<< "${DNS_RECORDS}" + else + echo "No DNS records found matching ${DNS_SUFFIX}" + fi else - echo "No DNS records found matching ${DNS_SUFFIX}" + echo "Skipping DNS cleanup - hosted cluster name not available" fi # Remove ExternalDNS WIF bindings