Skip to content

Commit

Permalink
Fix context issue during cleanup of kind clusters
Browse files Browse the repository at this point in the history
Signed-off-by: Pulkit Jain <[email protected]>
  • Loading branch information
jainpulkit22 committed Dec 13, 2024
1 parent 9a1a089 commit 8612cb2
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions ci/kind/kind-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -528,19 +528,26 @@ function destroy_external_servers {

function clean_kind {
echo "=== Cleaning up stale kind clusters ==="
read -a all_kind_clusters <<< $(kind get clusters)
for kind_cluster_name in "${all_kind_clusters[@]}"; do
creationTimestamp=$(kubectl get nodes --context kind-$kind_cluster_name -o json -l node-role.kubernetes.io/control-plane | \
jq -r '.items[0].metadata.creationTimestamp')
creation=$(printUnixTimestamp "$creationTimestamp")
now=$(date -u '+%s')
diff=$((now-creation))
timeout=$(($UNTIL_TIME_IN_MINS*60))
if [[ $diff -gt $timeout ]]; then
echo "=== kind ${kind_cluster_name} present from more than $UNTIL_TIME_IN_MINS minutes ==="
kind delete cluster --name $kind_cluster_name
fi
LOCK_FILE="$THIS_DIR/.kube/config.lock"
exec 200>"$LOCK_FILE"
flock 200
for context in $(kubectl config get-contexts -o name | grep 'kind-'); do
cluster_name=$(echo $context | sed 's/^kind-//')
creationTimestamp=$(kubectl get nodes --context $context -o json -l node-role.kubernetes.io/control-plane | \
jq -r '.items[0].metadata.creationTimestamp' || true)
if [[ -z $creationTimestamp ]]; then
continue
fi
creation=$(printUnixTimestamp "$creationTimestamp")
now=$(date -u '+%s')
diff=$((now-creation))
timeout=$(($UNTIL_TIME_IN_MINS*60))
if [[ $diff -gt $timeout ]]; then
echo "=== Cluster ${cluster_name} is present for more than $UNTIL_TIME_IN_MINS minutes ==="
kind delete cluster --name $cluster_name
fi
done
flock -u 200
}

if ! command -v kind &> /dev/null
Expand Down

0 comments on commit 8612cb2

Please sign in to comment.