@@ -88,7 +88,7 @@ BG_DELETE="${BG_DELETE:-true}"
88
88
89
89
[ " $1 " = " -dryrun" ] && DRY_RUN=" true"
90
90
91
- echo @@ ` timestamp` Starting cleanup.
91
+ echo @@ ` timestamp` Info: Starting cleanup.
92
92
script=" ${BASH_SOURCE[0]} "
93
93
scriptDir=" $( cd " $( dirname " ${script} " ) " > /dev/null 2>&1 ; pwd -P) "
94
94
source $PROJECT_ROOT /kubernetes/internal/utility.sh
@@ -110,6 +110,19 @@ function jobWaitAndKill {
110
110
[ ! -z " $( jobs -rp) " ] && kill -9 $( jobs -rp)
111
111
}
112
112
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
+
113
126
# use for kubectl delete of a specific name, exits silently if nothing found via 'get'
114
127
# usage: doDeleteByName [-n foobar] kind name
115
128
function doDeleteByName {
@@ -129,7 +142,7 @@ function doDeleteByName {
129
142
130
143
local ttextt=" "
131
144
[ " $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
133
146
cat $tmpfile
134
147
rm $tmpfile
135
148
@@ -157,7 +170,7 @@ function doDeleteByRange {
157
170
158
171
local ttextt=" "
159
172
[ " $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
161
174
cat $tmpfile
162
175
rm $tmpfile
163
176
@@ -209,14 +222,14 @@ waitForLabelPods() {
209
222
local mnow=mstart
210
223
local maxwaitsecs=$1
211
224
local pods
212
- echo " @@ ` timestamp` Waiting $maxwaitsecs for pods to stop running."
225
+ echo " @@ ` timestamp` Info: Waiting $maxwaitsecs for pods to stop running."
213
226
while [ $(( mnow - mstart)) -lt $maxwaitsecs ]; do
214
227
pods=($( kubectl get pods --all-namespaces -l $LABEL_SELECTOR -o jsonpath=' {range .items[*]}{.metadata.name} {end}' ) )
215
228
total=${# pods[*]}
216
229
if [ $total -eq 0 ] ; then
217
230
break
218
231
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 " .
220
233
fi
221
234
sleep 0.5
222
235
mnow=` date +%s`
@@ -240,7 +253,7 @@ deleteDomains() {
240
253
if [ " $DRY_RUN " = " true" ]; then
241
254
kubectl --all-namespaces=true get pods -l weblogic.serverName \
242
255
-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") }'
244
257
else
245
258
kubectl --all-namespaces=true get pods -l weblogic.serverName \
246
259
-o=jsonpath=' {range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}' \
@@ -302,7 +315,7 @@ deleteWebLogicPods() {
302
315
# - the delete order is order of NAMESPACED_TYPES and then NOT_NAMESPACED_TYPES
303
316
# - uses $1 as a temporary file
304
317
function deleteLabel {
305
- echo @@ ` timestamp` Delete resources with label $LABEL_SELECTOR .
318
+ echo @@ ` timestamp` Info: Delete resources with label $LABEL_SELECTOR .
306
319
307
320
# clean the output file first
308
321
@@ -315,6 +328,16 @@ function deleteLabel {
315
328
316
329
for resource_type in $NAMESPACED_TYPES
317
330
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
+
318
341
kubectl get $resource_type \
319
342
-l " $LABEL_SELECTOR " \
320
343
-o=jsonpath=' {range .items[*]}{.kind}{" "}{.metadata.name}{" -n "}{.metadata.namespace}{"\n"}{end}' \
@@ -392,11 +415,12 @@ function deleteByTypeAndLabel {
392
415
tempfile=" /tmp/$( basename $0 ) .tmp.$$ " # == /tmp/[script-file-name].tmp.[pid]
393
416
394
417
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 '."
396
420
deleteLabel " $tempfile -0"
397
421
398
422
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 '."
400
424
deleteLabel " $tempfile -1"
401
425
402
426
# TBD: This appears to hurt more than it helps. Doesn't protect against out of order deletes.
@@ -408,7 +432,7 @@ function deleteByTypeAndLabel {
408
432
409
433
if [ " $HANDLE_VOYAGER " = " true" ]; then
410
434
if [ ! " $DRY_RUN " = " true" ]; then
411
- echo @@ ` timestamp` Deleting voyager controller.
435
+ echo @@ ` timestamp` Info: Deleting voyager controller.
412
436
# calls script in utility.sh
413
437
deleteVoyagerOperator
414
438
fi
@@ -438,8 +462,8 @@ function deleteByTypeAndLabel {
438
462
# for no more than 60 seconds total.
439
463
#
440
464
# -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
443
467
# FAST_DELETE is overridden in this path.
444
468
#
445
469
function genericDelete {
@@ -456,8 +480,8 @@ function genericDelete {
456
480
fi
457
481
fi
458
482
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."
461
485
462
486
local artcount_no
463
487
local artcount_yes
@@ -467,6 +491,15 @@ function genericDelete {
467
491
468
492
local mstart=` date +%s`
469
493
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
+
470
503
while : ; do
471
504
resfile_no=" $TMP_DIR /kinv_filtered_nonamespace.out.tmp"
472
505
resfile_yes=" $TMP_DIR /kinv_filtered_yesnamespace.out.tmp"
@@ -490,22 +523,22 @@ function genericDelete {
490
523
mnow=` date +%s`
491
524
492
525
if [ $(( artcount_total)) -eq 0 ]; then
493
- echo " @@ ` timestamp` No artifacts found."
526
+ echo " @@ ` timestamp` Info: No artifacts found."
494
527
return 0
495
528
fi
496
529
497
530
if [ " $mode " = " -wait" ]; then
498
531
# just wait to see if artifacts go away on there own
499
532
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:"
501
534
502
535
cat $resfile_yes | awk ' { print "n=" $1 " " $2 }'
503
536
cat $resfile_no | awk ' { print $1 }'
504
537
505
538
else
506
539
# try to delete remaining artifacts
507
540
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 )."
509
542
510
543
if [ " $mode " = " -forceDelete" ]; then
511
544
local fast_delete_orig=" $FAST_DELETE "
@@ -563,9 +596,9 @@ function deleteHelmReleases {
563
596
helm version --short --client | grep v2
564
597
[[ $? == 0 ]] && HELM_VERSION=V2
565
598
[[ $? == 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) ]"
567
600
568
- echo @@ ` timestamp` Deleting installed helm charts
601
+ echo @@ ` timestamp` Info: Deleting installed helm charts
569
602
570
603
if [ " $HELM_VERSION " == " V2" ]; then
571
604
helm list --short | while read helm_name; do
@@ -594,7 +627,7 @@ function deleteHelmReleases {
594
627
595
628
# cleanup tiller artifacts
596
629
if [ " $SHARED_CLUSTER " = " true" ]; then
597
- echo @@ ` timestamp` Skipping tiller delete.
630
+ echo @@ ` timestamp` Info: Skipping tiller delete.
598
631
# TBD: According to MarkN no Tiller delete is needed.
599
632
# kubectl $FAST_DELETE -n kube-system delete deployment tiller-deploy --ignore-not-found=true
600
633
# kubectl $FAST_DELETE delete clusterrolebinding tiller-cluster-rule --ignore-not-found=true
@@ -605,7 +638,7 @@ function deleteHelmReleases {
605
638
606
639
FAST_DELETE=${FAST_DELETE:- --timeout=60s}
607
640
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 "
609
642
610
643
mkdir -p $TMP_DIR || exit 1
611
644
@@ -659,9 +692,9 @@ deleteByTypeAndLabel
659
692
# g_arg3 - keywords in deletable artifacts
660
693
#
661
694
662
- g_arg1=" all,cm,pvc,roles,rolebindings,serviceaccount,secrets,ingress"
695
+ g_arg1=" all,cm,pvc,roles,rolebindings,serviceaccount,secrets,ingress,deployments "
663
696
g_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 "
665
698
666
699
#
667
700
# 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
693
726
694
727
# Delete pv directories using a run (/sharedparent maps to PV_ROOT on the k8s cluster machines).
695
728
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.
697
730
# $SCRIPTPATH/job.sh "rm -fr /scratch/acceptance_test_pv"
698
731
$SCRIPTPATH /krun.sh -i openjdk:11-oracle -t 600 -m " ${PV_ROOT} :/sharedparent" -c ' rm -fr /sharedparent/*/acceptance_test_pv'
699
732
[ " $? " = " 0" ] || SUCCESS=" 1"
700
- echo @@ ` timestamp` SUCCESS=$SUCCESS
733
+ echo @@ ` timestamp` Info: SUCCESS=$SUCCESS
701
734
702
735
# Delete old test files owned by the current user.
703
736
704
- echo @@ ` timestamp` Deleting local $RESULT_DIR contents.
737
+ echo @@ ` timestamp` Info: Deleting local $RESULT_DIR contents.
705
738
rm -fr $RESULT_ROOT /* /acceptance_test_tmp
706
739
[ " $? " = " 0" ] || SUCCESS=" 1"
707
- echo @@ ` timestamp` SUCCESS=$SUCCESS
740
+ echo @@ ` timestamp` Info: SUCCESS=$SUCCESS
708
741
709
- echo @@ ` timestamp` Deleting /tmp/test_suite.\* files.
742
+ echo @@ ` timestamp` Info: Deleting /tmp/test_suite.\* files.
710
743
rm -f /tmp/test_suite.*
711
744
712
745
fi
@@ -725,5 +758,5 @@ if [ ! "$LEASE_ID" = "" ] && [ ! "$SUCCESS" = "0" ]; then
725
758
rm -f /tmp/release_lease.out
726
759
fi
727
760
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