@@ -19,7 +19,6 @@ COMMON OPTIONS:
1919 --scheduler-ns <NS> Scheduler namespace (if different from auto-detected)
2020 --dry-run Show what would be deleted (safe, no changes)
2121 --sequential Use sequential deletion (slower, default is parallel)
22- --force-finalizer Force cleanup of stuck resources
2322 --timeout <SECONDS> Deletion timeout (default: 60)
2423 -h, --help Show this help
2524
@@ -41,9 +40,6 @@ EXAMPLES:
4140 # Sequential deletion (slower but more controlled)
4241 $( basename $0 ) cpd --sequential
4342
44- # Fast deletion with forced cleanup
45- $( basename $0 ) cpd --force-finalizer
46-
4743WHAT GETS DELETED:
4844 • CP4D instance namespace (specified)
4945 • Operator namespace (default: <instance>-operators)
@@ -202,10 +198,6 @@ else
202198 command_usage 2
203199 fi
204200 ;;
205- --force-finalizer)
206- export FORCE_FINALIZER=true
207- shift 1
208- ;;
209201 --timeout* )
210202 if [[ " $1 " =~ " =" ]] && [ ! -z " ${1#* =} " ] && [ " ${1#* =: 0: 1} " != " -" ]; then
211203 export NAMESPACE_DELETE_TIMEOUT=" ${1#* =} "
@@ -272,7 +264,7 @@ wait_ns_deleted() {
272264 TIMEOUT=${NAMESPACE_DELETE_TIMEOUT:- 60}
273265 ELAPSED=0
274266 RETRY_COUNT=0
275- MAX_RETRIES=3
267+ MAX_RETRIES=10
276268 log " Waiting for deletion of namespace ${NS} (timeout: ${TIMEOUT} s)..."
277269
278270 while $( oc get ns ${NS} > /dev/null 2>&1 ) ; do
@@ -286,14 +278,13 @@ wait_ns_deleted() {
286278 # Run diagnostics
287279 diagnose_namespace_stuck ${NS}
288280
289- if [ " ${FORCE_FINALIZER} " = " true " ] && [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
281+ if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
290282 RETRY_COUNT=$(( RETRY_COUNT + 1 ))
291283 log_info " Attempting forced cleanup (attempt ${RETRY_COUNT} /${MAX_RETRIES} )..."
292284 force_remove_finalizers ${NS}
293285
294286 # Reset timeout for retry
295287 ELAPSED=0
296- TIMEOUT=300 # Shorter timeout for retries
297288 log " Waiting additional ${TIMEOUT} s after forced cleanup..."
298289 continue
299290 else
@@ -366,17 +357,15 @@ wait_multiple_ns_deleted() {
366357 if oc get ns ${ns} > /dev/null 2>&1 ; then
367358 failed_ns+=(" $ns " )
368359 log_warning " Namespace ${ns} still exists after timeout"
369- if [ " ${FORCE_FINALIZER} " = " true" ]; then
370- log_info " Applying forced cleanup to ${ns} ..."
371- force_remove_finalizers ${ns}
372- fi
360+ log_info " Applying forced cleanup to ${ns} ..."
361+ force_remove_finalizers ${ns}
373362 else
374363 log_success " Namespace ${ns} deleted successfully"
375364 fi
376365 done
377366
378- # If there are failed namespaces and force finalizer is enabled , wait a bit more
379- if [ ${# failed_ns[@]} -gt 0 ] && [ " ${FORCE_FINALIZER} " = " true " ] ; then
367+ # If there are failed namespaces, wait a bit more
368+ if [ ${# failed_ns[@]} -gt 0 ]; then
380369 log_info " Waiting additional 120s for forced cleanup to complete..."
381370 sleep 120
382371
@@ -392,18 +381,16 @@ wait_multiple_ns_deleted() {
392381
393382force_remove_finalizers () {
394383 NS=$1
395- if [ " ${FORCE_FINALIZER} " = " true" ]; then
396- log_info " Force removing finalizers for ${NS} namespace"
397-
398- # First, try to remove finalizers from blocking resources
399- force_remove_resource_finalizers ${NS}
400-
401- # Then remove namespace finalizers using oc patch
402- if oc get ns ${NS} > /dev/null 2>&1 ; then
403- log_info " Removing finalizers from namespace ${NS} ..."
404- oc patch ns ${NS} --type=merge -p ' {"metadata":{"finalizers":null}}' 2> /dev/null || true
405- log_success " Namespace finalizers removed for ${NS} "
406- fi
384+ log_info " Force removing finalizers for ${NS} namespace"
385+
386+ # First, try to remove finalizers from blocking resources
387+ force_remove_resource_finalizers ${NS}
388+
389+ # Then remove namespace finalizers using oc patch
390+ if oc get ns ${NS} > /dev/null 2>&1 ; then
391+ log_info " Removing finalizers from namespace ${NS} ..."
392+ oc patch ns ${NS} --type=merge -p ' {"metadata":{"finalizers":null}}' 2> /dev/null || true
393+ log_success " Namespace finalizers removed for ${NS} "
407394 fi
408395}
409396
0 commit comments