Skip to content

Commit 803bd1b

Browse files
committed
Fix critical bug: cleanup script not removing volume files
The cleanup script was looking for volume files in subdirectories: ${WORKING_DIR}/pool/${CLUSTER_NAME}/eci-xxx_master_0.qcow2 But dev-scripts creates them in flat structure: ${WORKING_DIR}/pool/eci-xxx_master_0.qcow2 This caused 120 orphaned volume files (~5.8TB) to accumulate on the CI runner because cleanup never found them to delete. Changes: - Look for volumes in flat pool directory (${WORKING_DIR}/pool/) - Match by filename pattern: ${CLUSTER_NAME}_*.{img,qcow2} - Refresh multiple pool types (cluster-specific, oooq_pool) - Updated verification to also check flat pool directory - Handle optional cluster subdirectories (for configs that use them) This ensures volume files are properly cleaned up after every job.
1 parent bd62cce commit 803bd1b

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

scripts/cleanup.sh

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ if [ -n "${WORKING_DIR:-}" ]; then
162162
fi
163163
fi
164164

165-
# Clean up volume files from cluster-specific pool directory
165+
# Clean up volume files for this cluster
166+
# Volume files are in flat structure: /opt/dev-scripts/pool/eci-XXXXXXXX_*.qcow2
167+
# NOT in subdirectory /opt/dev-scripts/pool/eci-XXXXXXXX/
166168
if [ -n "${WORKING_DIR:-}" ]; then
167-
POOL_DIR="${WORKING_DIR}/pool/${CLUSTER_NAME}"
169+
POOL_DIR="${WORKING_DIR}/pool"
168170
if [ -d "$POOL_DIR" ]; then
169171
info "Cleaning up volume files for cluster: ${CLUSTER_NAME}"
170172

171-
# Find and remove all volume files for this cluster
173+
# Find and remove all volume files for this cluster (in flat pool directory)
172174
VOLUME_FILES=$(find "$POOL_DIR" -maxdepth 1 -type f \( -name "${CLUSTER_NAME}_*.img" -o -name "${CLUSTER_NAME}_*.qcow2" \) 2>/dev/null || true)
173175

174176
if [ -n "$VOLUME_FILES" ]; then
@@ -181,14 +183,23 @@ if [ -n "${WORKING_DIR:-}" ]; then
181183
sudo rm -f "$vol_file" || warning " Failed to remove $vol_file"
182184
done <<< "$VOLUME_FILES"
183185

184-
# Refresh the cluster-specific pool to update libvirt's volume list
185-
# Try both new naming (-lz) and legacy naming (_pool)
186-
info " Refreshing libvirt storage pool..."
187-
sudo virsh pool-refresh "${CLUSTER_NAME}-lz" &>/dev/null || \
186+
# Refresh the storage pools to update libvirt's volume list
187+
# The pool might be cluster-specific or shared (oooq_pool)
188+
info " Refreshing libvirt storage pools..."
189+
sudo virsh pool-refresh "${CLUSTER_NAME}" &>/dev/null || true
190+
sudo virsh pool-refresh "${CLUSTER_NAME}-lz" &>/dev/null || true
188191
sudo virsh pool-refresh "${CLUSTER_NAME}_pool" &>/dev/null || true
192+
sudo virsh pool-refresh "oooq_pool" &>/dev/null || true
189193
else
190194
info " No volume files found for cleanup"
191195
fi
196+
197+
# Remove cluster-specific subdirectory if it exists and is empty
198+
# (some configurations might use subdirectories)
199+
CLUSTER_POOL_SUBDIR="${POOL_DIR}/${CLUSTER_NAME}"
200+
if [ -d "$CLUSTER_POOL_SUBDIR" ]; then
201+
rmdir "$CLUSTER_POOL_SUBDIR" 2>/dev/null && info " Removed empty pool subdirectory: $CLUSTER_POOL_SUBDIR" || true
202+
fi
192203
fi
193204
fi
194205

@@ -299,20 +310,27 @@ if [ -n "${WORKING_DIR:-}" ]; then
299310
fi
300311
fi
301312

302-
# Check for leftover volume files and pool directory
313+
# Check for leftover volume files in flat pool directory
303314
if [ -n "${WORKING_DIR:-}" ]; then
304-
POOL_DIR="${WORKING_DIR}/pool/${CLUSTER_NAME}"
315+
POOL_DIR="${WORKING_DIR}/pool"
305316
if [ -d "$POOL_DIR" ]; then
306-
warning "Found leftover pool directory: $POOL_DIR"
307317
LEFTOVER_VOLS=$(find "$POOL_DIR" -maxdepth 1 -type f \( -name "${CLUSTER_NAME}_*.img" -o -name "${CLUSTER_NAME}_*.qcow2" \) 2>/dev/null || true)
308318
if [ -n "$LEFTOVER_VOLS" ]; then
309-
echo " Leftover volume files:"
319+
warning "Found leftover volume files in pool:"
310320
echo "$LEFTOVER_VOLS" | while read -r vol; do
311321
[ -n "$vol" ] && echo " $(basename "$vol")"
312322
done
323+
else
324+
success "No leftover volume files found"
325+
fi
326+
327+
# Also check for cluster-specific subdirectory (might exist in some configs)
328+
CLUSTER_POOL_SUBDIR="${POOL_DIR}/${CLUSTER_NAME}"
329+
if [ -d "$CLUSTER_POOL_SUBDIR" ]; then
330+
warning "Found leftover pool subdirectory: $CLUSTER_POOL_SUBDIR"
313331
fi
314332
else
315-
success "No leftover pool directory found"
333+
success "Pool directory does not exist"
316334
fi
317335
fi
318336

0 commit comments

Comments
 (0)