@@ -88,7 +88,7 @@ BG_DELETE="${BG_DELETE:-true}"
8888
8989[ " $1 " = " -dryrun" ] && DRY_RUN=" true"
9090
91- echo @@ ` timestamp` Starting cleanup.
91+ echo @@ ` timestamp` Info: Starting cleanup.
9292script=" ${BASH_SOURCE[0]} "
9393scriptDir=" $( cd " $( dirname " ${script} " ) " > /dev/null 2>&1 ; pwd -P) "
9494source $PROJECT_ROOT /kubernetes/internal/utility.sh
@@ -110,6 +110,19 @@ function jobWaitAndKill {
110110 [ ! -z " $( jobs -rp) " ] && kill -9 $( jobs -rp)
111111}
112112
113+ # helper fn to speedup pvc deletes
114+ function patchPVCFinalizer() {
115+ while read line; do
116+ if [ ! " $DRY_RUN " = " true" ]; then
117+ set -x
118+ kubectl patch pvc $line -p ' {"metadata":{"finalizers":null}}'
119+ set +x
120+ else
121+ echo @@ ` timestamp` Info: DRYRUN: " kubectl patch pvc $line -p '{\" metadata\" :{\" finalizers\" :null}}'"
122+ fi
123+ done
124+ }
125+
113126# use for kubectl delete of a specific name, exits silently if nothing found via 'get'
114127# usage: doDeleteByName [-n foobar] kind name
115128function doDeleteByName {
@@ -129,7 +142,7 @@ function doDeleteByName {
129142
130143 local ttextt=" "
131144 [ " $DRY_RUN " = " true" ] && ttextt=" DRYRUN"
132- echo @@ ` timestamp` doDeleteByName $ttextt : kubectl $FAST_DELETE delete " $@ " --ignore-not-found
145+ echo @@ ` timestamp` Info: doDeleteByName $ttextt : kubectl $FAST_DELETE delete " $@ " --ignore-not-found
133146 cat $tmpfile
134147 rm $tmpfile
135148
@@ -157,7 +170,7 @@ function doDeleteByRange {
157170
158171 local ttextt=" "
159172 [ " $DRY_RUN " = " true" ] && ttextt=" DRYRUN"
160- echo @@ ` timestamp` doDeleteByRange $ttextt : kubectl $FAST_DELETE delete " $@ " --ignore-not-found
173+ echo @@ ` timestamp` Info: doDeleteByRange $ttextt : kubectl $FAST_DELETE delete " $@ " --ignore-not-found
161174 cat $tmpfile
162175 rm $tmpfile
163176
@@ -209,14 +222,14 @@ waitForLabelPods() {
209222 local mnow=mstart
210223 local maxwaitsecs=$1
211224 local pods
212- echo " @@ ` timestamp` Waiting $maxwaitsecs for pods to stop running."
225+ echo " @@ ` timestamp` Info: Waiting $maxwaitsecs for pods to stop running."
213226 while [ $(( mnow - mstart)) -lt $maxwaitsecs ]; do
214227 pods=($( kubectl get pods --all-namespaces -l $LABEL_SELECTOR -o jsonpath=' {range .items[*]}{.metadata.name} {end}' ) )
215228 total=${# pods[*]}
216229 if [ $total -eq 0 ] ; then
217230 break
218231 else
219- echo " @@ ` timestamp` There are $total running pods with label $LABEL_SELECTOR : $pods " .
232+ echo " @@ ` timestamp` Info: There are $total running pods with label $LABEL_SELECTOR : $pods " .
220233 fi
221234 sleep 0.5
222235 mnow=` date +%s`
@@ -240,7 +253,7 @@ deleteDomains() {
240253 if [ " $DRY_RUN " = " true" ]; then
241254 kubectl --all-namespaces=true get pods -l weblogic.serverName \
242255 -o=jsonpath=' {range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}' \
243- | awk ' { system("echo @@ dryrun : kubectl -n " $1 " exec " $2 " touch /tmp/diefast") }'
256+ | awk ' { system("echo @@ DRYRUN : kubectl -n " $1 " exec " $2 " touch /tmp/diefast") }'
244257 else
245258 kubectl --all-namespaces=true get pods -l weblogic.serverName \
246259 -o=jsonpath=' {range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}' \
@@ -302,7 +315,7 @@ deleteWebLogicPods() {
302315# - the delete order is order of NAMESPACED_TYPES and then NOT_NAMESPACED_TYPES
303316# - uses $1 as a temporary file
304317function deleteLabel {
305- echo @@ ` timestamp` Delete resources with label $LABEL_SELECTOR .
318+ echo @@ ` timestamp` Info: Delete resources with label $LABEL_SELECTOR .
306319
307320 # clean the output file first
308321
@@ -315,6 +328,16 @@ function deleteLabel {
315328
316329 for resource_type in $NAMESPACED_TYPES
317330 do
331+ # patch PVCs to speedup their deletion
332+ if [ " $resource_type " = " pvc" ]; then
333+ echo " @@ ` timestamp` Info: Disabling finalizers on pvc resources to speed up their deletion (LABEL_SELECTOR='$LABEL_SELECTOR ')."
334+ kubectl get pvc \
335+ -l " $LABEL_SELECTOR " \
336+ -o=jsonpath=' {range .items[*]}{.metadata.name}{" -n "}{.metadata.namespace}{"\n"}{end}' \
337+ --all-namespaces=true \
338+ | patchPVCFinalizer
339+ fi
340+
318341 kubectl get $resource_type \
319342 -l " $LABEL_SELECTOR " \
320343 -o=jsonpath=' {range .items[*]}{.kind}{" "}{.metadata.name}{" -n "}{.metadata.namespace}{"\n"}{end}' \
@@ -392,11 +415,12 @@ function deleteByTypeAndLabel {
392415 tempfile=" /tmp/$( basename $0 ) .tmp.$$ " # == /tmp/[script-file-name].tmp.[pid]
393416
394417 LABEL_SELECTOR=" weblogic.domainUID"
395- echo " @@ Deleting wls domain resources by LABEL_SELECTOR='$LABEL_SELECTOR ', NAMESPACED_TYPES='$NAMESPACED_TYPES ', NOT_NAMESPACED_TYPES='$NOT_NAMESPACED_TYPES '."
418+
419+ echo " @@ ` timestamp` Info: Deleting wls domain resources by LABEL_SELECTOR='$LABEL_SELECTOR ', NAMESPACED_TYPES='$NAMESPACED_TYPES ', NOT_NAMESPACED_TYPES='$NOT_NAMESPACED_TYPES '."
396420 deleteLabel " $tempfile -0"
397421
398422 LABEL_SELECTOR=" weblogic.operatorName"
399- echo " @@ Deleting wls operator resources by LABEL_SELECTOR='$LABEL_SELECTOR ', NAMESPACED_TYPES='$NAMESPACED_TYPES ', NOT_NAMESPACED_TYPES='$NOT_NAMESPACED_TYPES '."
423+ echo " @@ ` timestamp ` Info: Deleting wls operator resources by LABEL_SELECTOR='$LABEL_SELECTOR ', NAMESPACED_TYPES='$NAMESPACED_TYPES ', NOT_NAMESPACED_TYPES='$NOT_NAMESPACED_TYPES '."
400424 deleteLabel " $tempfile -1"
401425
402426 # TBD: This appears to hurt more than it helps. Doesn't protect against out of order deletes.
@@ -408,7 +432,7 @@ function deleteByTypeAndLabel {
408432
409433 if [ " $HANDLE_VOYAGER " = " true" ]; then
410434 if [ ! " $DRY_RUN " = " true" ]; then
411- echo @@ ` timestamp` Deleting voyager controller.
435+ echo @@ ` timestamp` Info: Deleting voyager controller.
412436 # calls script in utility.sh
413437 deleteVoyagerOperator
414438 fi
@@ -438,8 +462,8 @@ function deleteByTypeAndLabel {
438462# for no more than 60 seconds total.
439463#
440464# -forceDelete: Try delete objects using "--force=true" and
441- # "--grace-period=0" for no more than 60 seconds total.
442- # Note that this is incompatible with "FAST_DELETE" so
465+ # "--grace-period=0" for no more than 60 seconds total.
466+ # Note that this is incompatible with "FAST_DELETE" so
443467# FAST_DELETE is overridden in this path.
444468#
445469function genericDelete {
@@ -456,8 +480,8 @@ function genericDelete {
456480 fi
457481 fi
458482
459- echo " @@ ` timestamp` In genericDelete with mode '$mode '"
460- echo " @@ ` timestamp` Waiting up to $maxwaitsecs seconds for ${1:? } and ${2:? } artifacts that contain string ${3:? } to delete."
483+ echo " @@ ` timestamp` Info: In genericDelete with mode '$mode '"
484+ echo " @@ ` timestamp` Info: Waiting up to $maxwaitsecs seconds for ${1:? } and ${2:? } artifacts that contain string ${3:? } to delete."
461485
462486 local artcount_no
463487 local artcount_yes
@@ -467,6 +491,15 @@ function genericDelete {
467491
468492 local mstart=` date +%s`
469493
494+ # patch PVCs to speedup their deletion
495+ if [ ! " $1 " = " ${1/ pvc// } " ]; then
496+ echo " @@ ` timestamp` Info: Disabling finalizers on pvc resources to speed up their deletion (filter='${3} ')."
497+ kubectl get pvc \
498+ -o=jsonpath=' {range .items[*]}{.metadata.name}{" -n "}{.metadata.namespace}{"\n"}{end}' \
499+ --all-namespaces=true \
500+ | egrep -e " ($3 )" | patchPVCFinalizer
501+ fi
502+
470503 while : ; do
471504 resfile_no=" $TMP_DIR /kinv_filtered_nonamespace.out.tmp"
472505 resfile_yes=" $TMP_DIR /kinv_filtered_yesnamespace.out.tmp"
@@ -490,22 +523,22 @@ function genericDelete {
490523 mnow=` date +%s`
491524
492525 if [ $(( artcount_total)) -eq 0 ]; then
493- echo " @@ ` timestamp` No artifacts found."
526+ echo " @@ ` timestamp` Info: No artifacts found."
494527 return 0
495528 fi
496529
497530 if [ " $mode " = " -wait" ]; then
498531 # just wait to see if artifacts go away on there own
499532
500- echo " @@ ` timestamp` Waiting for $artcount_total artifacts to delete. Wait time $(( mnow - mstart)) seconds (max=$maxwaitsecs ). Waiting for:"
533+ echo " @@ ` timestamp` Info: Waiting for $artcount_total artifacts to delete. Wait time $(( mnow - mstart)) seconds (max=$maxwaitsecs ). Waiting for:"
501534
502535 cat $resfile_yes | awk ' { print "n=" $1 " " $2 }'
503536 cat $resfile_no | awk ' { print $1 }'
504537
505538 else
506539 # try to delete remaining artifacts
507540
508- echo " @@ ` timestamp` Trying to delete ${artcount_total} leftover artifacts, including ${artcount_yes} namespaced artifacts and ${artcount_no} non-namespaced artifacts, wait time $(( mnow - mstart)) seconds (max=$maxwaitsecs )."
541+ echo " @@ ` timestamp` Info: Trying to delete ${artcount_total} leftover artifacts, including ${artcount_yes} namespaced artifacts and ${artcount_no} non-namespaced artifacts, wait time $(( mnow - mstart)) seconds (max=$maxwaitsecs )."
509542
510543 if [ " $mode " = " -forceDelete" ]; then
511544 local fast_delete_orig=" $FAST_DELETE "
@@ -563,9 +596,9 @@ function deleteHelmReleases {
563596 helm version --short --client | grep v2
564597 [[ $? == 0 ]] && HELM_VERSION=V2
565598 [[ $? == 1 ]] && HELM_VERSION=V3
566- echo " @@ ` timestamp` Detected Helm Version [$( helm version --short --client) ]"
599+ echo " @@ ` timestamp` Info: Detected Helm Version [$( helm version --short --client) ]"
567600
568- echo @@ ` timestamp` Deleting installed helm charts
601+ echo @@ ` timestamp` Info: Deleting installed helm charts
569602
570603 if [ " $HELM_VERSION " == " V2" ]; then
571604 helm list --short | while read helm_name; do
@@ -594,7 +627,7 @@ function deleteHelmReleases {
594627
595628 # cleanup tiller artifacts
596629 if [ " $SHARED_CLUSTER " = " true" ]; then
597- echo @@ ` timestamp` Skipping tiller delete.
630+ echo @@ ` timestamp` Info: Skipping tiller delete.
598631 # TBD: According to MarkN no Tiller delete is needed.
599632 # kubectl $FAST_DELETE -n kube-system delete deployment tiller-deploy --ignore-not-found=true
600633 # kubectl $FAST_DELETE delete clusterrolebinding tiller-cluster-rule --ignore-not-found=true
@@ -605,7 +638,7 @@ function deleteHelmReleases {
605638
606639FAST_DELETE=${FAST_DELETE:- --timeout=60s}
607640
608- echo " @@ ` timestamp` RESULT_ROOT=$RESULT_ROOT TMP_DIR=$TMP_DIR RESULT_DIR=$RESULT_DIR PROJECT_ROOT=$PROJECT_ROOT PV_ROOT=$PV_ROOT "
641+ echo " @@ ` timestamp` Info: RESULT_ROOT=$RESULT_ROOT TMP_DIR=$TMP_DIR RESULT_DIR=$RESULT_DIR PROJECT_ROOT=$PROJECT_ROOT PV_ROOT=$PV_ROOT "
609642
610643mkdir -p $TMP_DIR || exit 1
611644
@@ -659,9 +692,9 @@ deleteByTypeAndLabel
659692# g_arg3 - keywords in deletable artifacts
660693#
661694
662- g_arg1=" all,cm,pvc,roles,rolebindings,serviceaccount,secrets,ingress"
695+ g_arg1=" all,cm,pvc,roles,rolebindings,serviceaccount,secrets,ingress,deployments "
663696g_arg2=" crd,pv,ns,clusterroles,clusterrolebindings"
664- g_arg3=" logstash|kibana|elastisearch|weblogic|elk|domain|traefik|voyager|apache-webtier|mysql|test|opns"
697+ g_arg3=" Namespace/ns-| logstash|kibana|elastisearch|weblogic|elk|domain|traefik|voyager|apache-webtier|mysql|test|opns|oracle-db|rcu "
665698
666699#
667700# Phase 1 (continued): wait 15 seconds to see if artifacts dissappear naturally due to phase 1 effort
@@ -693,20 +726,20 @@ if [ "${DELETE_FILES:-true}" = "true" ] && [ "$DRY_RUN" = "false" ]; then
693726
694727 # Delete pv directories using a run (/sharedparent maps to PV_ROOT on the k8s cluster machines).
695728
696- echo @@ ` timestamp` Launching run to delete all pv contents. This runs in the k8s cluster, /sharedparent mounts PV_ROOT.
729+ echo @@ ` timestamp` Info: Launching run to delete all pv contents. This runs in the k8s cluster, /sharedparent mounts PV_ROOT.
697730 # $SCRIPTPATH/job.sh "rm -fr /scratch/acceptance_test_pv"
698731 $SCRIPTPATH /krun.sh -i openjdk:11-oracle -t 600 -m " ${PV_ROOT} :/sharedparent" -c ' rm -fr /sharedparent/*/acceptance_test_pv'
699732 [ " $? " = " 0" ] || SUCCESS=" 1"
700- echo @@ ` timestamp` SUCCESS=$SUCCESS
733+ echo @@ ` timestamp` Info: SUCCESS=$SUCCESS
701734
702735 # Delete old test files owned by the current user.
703736
704- echo @@ ` timestamp` Deleting local $RESULT_DIR contents.
737+ echo @@ ` timestamp` Info: Deleting local $RESULT_DIR contents.
705738 rm -fr $RESULT_ROOT /* /acceptance_test_tmp
706739 [ " $? " = " 0" ] || SUCCESS=" 1"
707- echo @@ ` timestamp` SUCCESS=$SUCCESS
740+ echo @@ ` timestamp` Info: SUCCESS=$SUCCESS
708741
709- echo @@ ` timestamp` Deleting /tmp/test_suite.\* files.
742+ echo @@ ` timestamp` Info: Deleting /tmp/test_suite.\* files.
710743 rm -f /tmp/test_suite.*
711744
712745fi
@@ -725,5 +758,5 @@ if [ ! "$LEASE_ID" = "" ] && [ ! "$SUCCESS" = "0" ]; then
725758 rm -f /tmp/release_lease.out
726759fi
727760
728- echo @@ ` timestamp` Exiting after $SECONDS seconds with status $SUCCESS
729- exit $SUCCESS
761+ echo @@ ` timestamp` Info: Exiting after $SECONDS seconds with status $SUCCESS
762+ exit $SUCCESS
0 commit comments