@@ -253,11 +253,44 @@ if [ -n "${WORKING_DIR:-}" ]; then
253253fi
254254
255255# Clean up cluster-specific libvirt storage pools
256- # - ${CLUSTER_NAME}: dev-scripts pool (shared by masters and Landing Zone with flat structure)
257- # - ${CLUSTER_NAME}-lz: Legacy separate Landing Zone pool (backwards compatibility)
258- # - ${CLUSTER_NAME}_pool: Legacy separate Landing Zone pool (backwards compatibility)
259- # Note: New deployments only create ${CLUSTER_NAME} pool, but we check all for cleanup
256+ # Find all pools that point to our cluster directory, regardless of name
257+ # Dev-scripts may create pools with various names (oooq_pool, ${CLUSTER_NAME}, etc.)
258+ CLUSTER_POOL_PATH=" "
259+ if [ -n " ${WORKING_DIR:- } " ]; then
260+ if [[ " ${WORKING_DIR} " == * " /clusters/${CLUSTER_NAME} " ]]; then
261+ CLUSTER_POOL_PATH=" ${WORKING_DIR} /pool"
262+ elif [ -n " ${BASE_WORKING_DIR:- } " ]; then
263+ CLUSTER_POOL_PATH=" ${BASE_WORKING_DIR} /clusters/${CLUSTER_NAME} /pool"
264+ fi
265+ fi
266+
267+ # Build list of pools to clean up
268+ POOLS_TO_CLEAN=()
269+
270+ # Add standard pool names we might have created
260271for POOL_NAME in " ${CLUSTER_NAME} " " ${CLUSTER_NAME} -lz" " ${CLUSTER_NAME} _pool" ; do
272+ if sudo virsh pool-uuid " $POOL_NAME " > /dev/null 2>&1 ; then
273+ POOLS_TO_CLEAN+=(" $POOL_NAME " )
274+ fi
275+ done
276+
277+ # Also find any pool pointing to our cluster-specific path (handles oooq_pool, etc.)
278+ if [ -n " $CLUSTER_POOL_PATH " ]; then
279+ while IFS= read -r pool; do
280+ if [ -n " $pool " ]; then
281+ 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 " )
287+ fi
288+ fi
289+ fi
290+ done < <( sudo virsh pool-list --all --name)
291+ fi
292+
293+ for POOL_NAME in " ${POOLS_TO_CLEAN[@]} " ; do
261294 if sudo virsh pool-uuid " $POOL_NAME " > /dev/null 2>&1 ; then
262295 info " Removing libvirt storage pool: $POOL_NAME "
263296
@@ -378,14 +411,31 @@ if [ -n "${WORKING_DIR:-}" ]; then
378411 fi
379412fi
380413
381- # Check for leftover pool definitions (dev-scripts pool and legacy Landing Zone pools )
414+ # Check for leftover pool definitions (by name or by path )
382415LEFTOVER_POOLS=" "
416+
417+ # Check standard pool names
383418for POOL_NAME in " ${CLUSTER_NAME} " " ${CLUSTER_NAME} -lz" " ${CLUSTER_NAME} _pool" ; do
384419 if sudo virsh pool-uuid " $POOL_NAME " > /dev/null 2>&1 ; then
385420 LEFTOVER_POOLS=" ${LEFTOVER_POOLS}${POOL_NAME} "
386421 fi
387422done
388423
424+ # Check for any pool pointing to cluster path (handles oooq_pool, etc.)
425+ if [ -n " $CLUSTER_POOL_PATH " ]; then
426+ while IFS= read -r pool; do
427+ if [ -n " $pool " ]; then
428+ 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} "
433+ fi
434+ fi
435+ fi
436+ done < <( sudo virsh pool-list --all --name)
437+ fi
438+
389439if [ -n " $LEFTOVER_POOLS " ]; then
390440 warning " Found leftover pool definition(s): $LEFTOVER_POOLS "
391441else
0 commit comments