Skip to content

Commit 1d7d3dd

Browse files
committed
address review comments
1 parent 5107f09 commit 1d7d3dd

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

KUBERNETES_LKG

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/kops_lkg_ccm.sh

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
# This script deploys a Kubernetes cluster using kops with configurable version targets.
1818
# Modes:
1919
# lkg-k8s-local-gcp: LKG K8s version + Local CCM build
20-
# latest-k8s-lkg-gcp: Latest Stable K8s + Stock/LKG CCM (Kops default)
20+
# latest-k8s-lkg-gcp: Latest Stable K8s + Stock/LKG CCM (Kops default) (Note: This requires kops to support the latest K8s version; kops releases may lag behind upstream)
2121
# stock: Stock Kops behavior (Kops default K8s + Kops default CCM)
22+
#
23+
# Cluster Lifecycle:
24+
# By default (DELETE_CLUSTER=true), the cluster is deleted if this script fails or is interrupted.
25+
# On success, the cluster is PRESERVED (not deleted) to allow for testing/debugging.
26+
# Set DELETE_CLUSTER=false to preserve the cluster even on failure.
2227

2328
set -o errexit
2429
set -o nounset
@@ -34,7 +39,7 @@ usage() {
3439
echo "Environment variables:"
3540
echo " GCP_PROJECT (Required) GCP Project ID"
3641
echo " CLUSTER_NAME (Required) Cluster name (e.g. my-cluster.k8s.local)"
37-
echo " DELETE_CLUSTER (Optional) Set to 'false' to keep the cluster running (default: true)"
42+
echo " DELETE_CLUSTER (Optional) Default 'true': delete on failure, keep on success. Set 'false' to always keep."
3843
echo " KOPS_STATE_STORE (Optional) GCS bucket for kops state"
3944
echo " GCP_LOCATION (Optional) Region (default: us-central1)"
4045
echo " ZONES (Optional) Zones (default: us-central1-a)"
@@ -116,12 +121,8 @@ K8S_VERSION_ARG=""
116121

117122
case "${MODE}" in
118123
lkg-k8s-local-gcp)
119-
LKG_FILE="${REPO_ROOT}/KUBERNETES_LKG"
120-
if [[ ! -f "${LKG_FILE}" ]]; then
121-
echo "Error: ${LKG_FILE} not found!"
122-
exit 1
123-
fi
124-
K8S_VERSION=$(cat "${LKG_FILE}")
124+
# Fetch latest stable version as the LKG version for now
125+
K8S_VERSION=$(curl -sL https://dl.k8s.io/release/stable.txt)
125126
echo "Using LKG K8s Version: ${K8S_VERSION}"
126127
K8S_VERSION_ARG="--kubernetes-version=${K8S_VERSION}"
127128
BUILD_LOCAL_CCM=true
@@ -205,33 +206,11 @@ kops create cluster \
205206
kops update cluster "${CLUSTER_NAME}" --yes
206207

207208
echo "Cluster creation initiated. Waiting for readiness..."
208-
# We can optionally wait here, but kops update returns before cluster is fully healthy usually.
209-
# kops validate cluster could be used.
209+
# Validate the cluster and wait for up to 15 minutes for it to become ready
210+
kops validate cluster --name "${CLUSTER_NAME}" --wait 15m
210211

211212
if [[ "${DELETE_CLUSTER}" == "true" ]]; then
212-
# Prevent trap from running immediately if we want to hold it?
213-
# Actually trap runs on EXIT. If we want to keep it effectively for the test duration we usually wait or run tests.
214-
# For now, this script just creates it.
215-
# If DELETE_CLUSTER is true, we should probably wait a bit or provide a way to pause?
216-
# kops_local_ccm.sh has:
217-
# if [[ "${DELETE_CLUSTER:-}" == "true" ]]; then
218-
# # Don't delete again in trap
219-
# DELETE_CLUSTER=false
220-
# fi
221-
# Wait, kops_local_ccm.sh's trap logic is:
222-
# function cleanup { if DELETE_CLUSTER==true ... }
223-
# And at the end it sets DELETE_CLUSTER=false.
224-
# This implies kops_local_ccm.sh is INTENDED to keep the cluster running if successful?
225-
# User said "The script needs to support...", implying it's a deployment script.
226-
# I will stick to the same pattern: delete on error, but if successful, maybe keep it?
227-
# Or maybe it just creates it and exits?
228-
# "kops_local_ccm.sh" ends with:
229-
# if [[ "${DELETE_CLUSTER:-}" == "true" ]]; then
230-
# DELETE_CLUSTER=false
231-
# fi
232-
# This means if it reaches the end successfully, it disables the trap deletion.
233-
# So the default behavior is "Delete on Failure, Keep on Success" (if DELETE_CLUSTER starts as true).
234-
235-
# Let's match that behavior.
213+
# Success! Disable the cleanup trap so the cluster persists.
214+
# The trap only deletes the cluster if DELETE_CLUSTER is still true (meaning script failed or was interrupted).
236215
DELETE_CLUSTER="false"
237216
fi

0 commit comments

Comments
 (0)