Skip to content

Commit c5fbed8

Browse files
committed
Reuse dev-scripts pools to avoid conflicts
Dev-scripts creates pools with varying names (oooq_pool, eci-XXXX-1). Our script now finds and reuses whatever pool points to our cluster path instead of trying to create a new one, avoiding conflicts. Also fixes cleanup to remove pools by path, not just by name.
1 parent 8522925 commit c5fbed8

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

scripts/cleanup.sh

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,15 @@ fi
255255
# Clean up cluster-specific libvirt storage pools
256256
# Find all pools that point to our cluster directory, regardless of name
257257
# Dev-scripts may create pools with various names (oooq_pool, ${CLUSTER_NAME}, etc.)
258-
CLUSTER_POOL_PATH=""
258+
# and various paths (pool/, landing-zone/, etc.)
259+
CLUSTER_POOL_PATHS=()
259260
if [ -n "${WORKING_DIR:-}" ]; then
260261
if [[ "${WORKING_DIR}" == *"/clusters/${CLUSTER_NAME}" ]]; then
261-
CLUSTER_POOL_PATH="${WORKING_DIR}/pool"
262+
CLUSTER_POOL_PATHS+=("${WORKING_DIR}/pool")
263+
CLUSTER_POOL_PATHS+=("${WORKING_DIR}/landing-zone/${CLUSTER_NAME}")
262264
elif [ -n "${BASE_WORKING_DIR:-}" ]; then
263-
CLUSTER_POOL_PATH="${BASE_WORKING_DIR}/clusters/${CLUSTER_NAME}/pool"
265+
CLUSTER_POOL_PATHS+=("${BASE_WORKING_DIR}/clusters/${CLUSTER_NAME}/pool")
266+
CLUSTER_POOL_PATHS+=("${BASE_WORKING_DIR}/clusters/${CLUSTER_NAME}/landing-zone/${CLUSTER_NAME}")
264267
fi
265268
fi
266269

@@ -274,18 +277,21 @@ for POOL_NAME in "${CLUSTER_NAME}" "${CLUSTER_NAME}-lz" "${CLUSTER_NAME}_pool";
274277
fi
275278
done
276279

277-
# Also find any pool pointing to our cluster-specific path (handles oooq_pool, etc.)
278-
if [ -n "$CLUSTER_POOL_PATH" ]; then
280+
# Also find any pool pointing to our cluster-specific paths (handles oooq_pool, eci-XXXX-1, etc.)
281+
if [ ${#CLUSTER_POOL_PATHS[@]} -gt 0 ]; then
279282
while IFS= read -r pool; do
280283
if [ -n "$pool" ]; then
281284
POOL_PATH_CHECK=$(sudo virsh pool-dumpxml "$pool" 2>/dev/null | grep -oP '(?<=<path>).*(?=</path>)' || echo "")
282-
if [ "$POOL_PATH_CHECK" = "$CLUSTER_POOL_PATH" ]; then
283-
# Check if not already in the list
284-
if [[ ! " ${POOLS_TO_CLEAN[@]} " =~ " ${pool} " ]]; then
285-
info "Found pool '$pool' pointing to cluster path, will clean it up"
286-
POOLS_TO_CLEAN+=("$pool")
285+
for cluster_path in "${CLUSTER_POOL_PATHS[@]}"; do
286+
if [ "$POOL_PATH_CHECK" = "$cluster_path" ]; then
287+
# Check if not already in the list
288+
if [[ ! " ${POOLS_TO_CLEAN[@]} " =~ " ${pool} " ]]; then
289+
info "Found pool '$pool' pointing to cluster path $cluster_path, will clean it up"
290+
POOLS_TO_CLEAN+=("$pool")
291+
fi
292+
break
287293
fi
288-
fi
294+
done
289295
fi
290296
done < <(sudo virsh pool-list --all --name)
291297
fi
@@ -421,17 +427,20 @@ for POOL_NAME in "${CLUSTER_NAME}" "${CLUSTER_NAME}-lz" "${CLUSTER_NAME}_pool";
421427
fi
422428
done
423429

424-
# Check for any pool pointing to cluster path (handles oooq_pool, etc.)
425-
if [ -n "$CLUSTER_POOL_PATH" ]; then
430+
# Check for any pool pointing to cluster paths (handles oooq_pool, eci-XXXX-1, etc.)
431+
if [ ${#CLUSTER_POOL_PATHS[@]} -gt 0 ]; then
426432
while IFS= read -r pool; do
427433
if [ -n "$pool" ]; then
428434
POOL_PATH_CHECK=$(sudo virsh pool-dumpxml "$pool" 2>/dev/null | grep -oP '(?<=<path>).*(?=</path>)' || echo "")
429-
if [ "$POOL_PATH_CHECK" = "$CLUSTER_POOL_PATH" ]; then
430-
# Add if not already in list
431-
if [[ ! "$LEFTOVER_POOLS" =~ $pool ]]; then
432-
LEFTOVER_POOLS="${LEFTOVER_POOLS}${pool} "
435+
for cluster_path in "${CLUSTER_POOL_PATHS[@]}"; do
436+
if [ "$POOL_PATH_CHECK" = "$cluster_path" ]; then
437+
# Add if not already in list
438+
if [[ ! "$LEFTOVER_POOLS" =~ $pool ]]; then
439+
LEFTOVER_POOLS="${LEFTOVER_POOLS}${pool} "
440+
fi
441+
break
433442
fi
434-
fi
443+
done
435444
fi
436445
done < <(sudo virsh pool-list --all --name)
437446
fi

0 commit comments

Comments
 (0)