Skip to content

Commit e1c023d

Browse files
author
Lily He
committed
update cleanup.sh
1 parent 81dbcd9 commit e1c023d

File tree

2 files changed

+66
-74
lines changed

2 files changed

+66
-74
lines changed

kubernetes/delete-weblogic-domain-resources.sh

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -53,47 +53,6 @@ cat << EOF
5353
EOF
5454
}
5555

56-
#
57-
# get voyager related resources of one domain
58-
#
59-
# Usage:
60-
# getVoyagerOfDomain domainName outfilename
61-
function getVoyagerOfDomain {
62-
local voyagerIngressName="ingress.voyager.appscode.com"
63-
local domainName=$1
64-
local ns=`kubectl get ingress.voyager.appscode.com --all-namespaces | grep $domainName | awk '{ print $1 }'`
65-
if [ -n "$ns" ]; then
66-
echo $voyagerIngressName $domainName-voyager -n $ns >> $2
67-
fi
68-
}
69-
70-
#
71-
# get voyager related resources
72-
#
73-
# Usage:
74-
# getVoyagerRes domainA,domainB,... outfilename
75-
# getVoyagerRes all outfilename
76-
function getVoyagerRes {
77-
if [ "$1" = "all" ]; then
78-
resList=`kubectl get ingress.voyager.appscode.com --all-namespaces | awk '{print $2}'`
79-
for resName in $resList
80-
do
81-
if [ $resName != 'NAME' ]; then
82-
tail="-voyager"
83-
len=${#resName}-${#tail}
84-
domainName=${resName:0:len}
85-
getVoyagerOfDomain $domainName $2
86-
fi
87-
done
88-
else
89-
IFS=',' read -r -a array <<< "$1"
90-
for domainName in "${array[@]}"
91-
do
92-
getVoyagerOfDomain $domainName $2
93-
done
94-
fi
95-
}
96-
9756
#
9857
# getDomainResources domain(s) outfilename
9958
#
@@ -129,6 +88,11 @@ function getDomainResources {
12988
NAMESPACED_TYPES="domain,$NAMESPACED_TYPES"
13089
fi
13190

91+
VOYAGER_ING_NAME="ingresses.voyager.appscode.com"
92+
if [ `kubectl get crd $VOYAGER_ING_NAME |grep $VOYAGER_ING_NAME | wc -l` = 1 ]; then
93+
NAMESPACED_TYPES="$VOYAGER_ING_NAME,$NAMESPACED_TYPES"
94+
fi
95+
13296
kubectl get $NAMESPACED_TYPES \
13397
-l "$LABEL_SELECTOR" \
13498
-o=jsonpath='{range .items[*]}{.kind}{" "}{.metadata.name}{" -n "}{.metadata.namespace}{"\n"}{end}' \
@@ -142,9 +106,6 @@ function getDomainResources {
142106
-l "$LABEL_SELECTOR" \
143107
-o=jsonpath='{range .items[*]}{.kind}{" "}{.metadata.name}{"\n"}{end}' \
144108
--all-namespaces=true >> $2
145-
146-
# get all voyager-related resources
147-
getVoyagerRes $1 $2
148109
}
149110

150111
#
@@ -243,9 +204,9 @@ function deleteDomains {
243204
# for each namespace with leftover resources, try delete them
244205
cat $tempfile | awk '{ print $4 }' | grep -v "^$" | sort -u | while read line; do
245206
if [ "$test_mode" = "true" ]; then
246-
echo kubectl -n $line delete $NAMESPACED_TYPES,ingress.voyager.appscode.com -l "$LABEL_SELECTOR"
207+
echo kubectl -n $line delete $NAMESPACED_TYPES -l "$LABEL_SELECTOR"
247208
else
248-
kubectl -n $line delete $NAMESPACED_TYPES,ingress.voyager.appscode.com -l "$LABEL_SELECTOR"
209+
kubectl -n $line delete $NAMESPACED_TYPES -l "$LABEL_SELECTOR"
249210
fi
250211
done
251212

@@ -307,3 +268,4 @@ if [ ! -x "$(command -v kubectl)" ]; then
307268
fi
308269

309270
deleteDomains "${domains}" "${maxwaitsecs:-$default_maxwaitsecs}"
271+

src/integration-tests/bash/cleanup.sh

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function getResWithLabel {
7878
# deleteResWithLabel outputfile
7979
#
8080
function deleteResWithLabel {
81+
echo @@ Delete resources with label $LABEL_SELECTOR.
8182
# clean the output file first
8283
if [ -e $1 ]; then
8384
rm $1
@@ -86,43 +87,51 @@ function deleteResWithLabel {
8687
getResWithLabel $1
8788
# delete namespaced types
8889
cat $1 | awk '{ print $4 }' | grep -v "^$" | sort -u | while read line; do
89-
if [ "$test_mode" = "true" ]; then
90-
echo kubectl -n $line delete $NAMESPACED_TYPES -l "$LABEL_SELECTOR"
91-
else
92-
kubectl -n $line delete $NAMESPACED_TYPES -l "$LABEL_SELECTOR"
93-
fi
90+
kubectl -n $line delete $NAMESPACED_TYPES -l "$LABEL_SELECTOR"
9491
done
9592

9693
# delete non-namespaced types
9794
local no_namespace_count=`grep -c -v " -n " $1`
9895
if [ ! "$no_namespace_count" = "0" ]; then
99-
if [ "$test_mode" = "true" ]; then
100-
echo kubectl delete $NOT_NAMESPACED_TYPES -l "$LABEL_SELECTOR"
96+
kubectl delete $NOT_NAMESPACED_TYPES -l "$LABEL_SELECTOR"
97+
fi
98+
99+
echo "@@ Waiting for pods to stop running."
100+
local total=0
101+
for count in {1..100}; do
102+
pods=($(kubectl get pods --all-namespaces -l weblogic.domainUID -o jsonpath='{range .items[*]}{.metadata.name} {end}'))
103+
total=${#pods[*]}
104+
if [ $total -eq 0 ] ; then
105+
break
101106
else
102-
kubectl delete $NOT_NAMESPACED_TYPES -l "$LABEL_SELECTOR"
107+
echo "@@ There are still $total running pods with label $LABEL_SELECTOR."
103108
fi
104-
fi
105-
}
109+
sleep 3
110+
done
106111

107-
#
108-
# deleteWLSOperators
109-
#
110-
function deleteWLSOperators {
111-
local tempfile="/tmp/$(basename $0).tmp.$$" # == /tmp/[script-file-name].tmp.[pid]
112-
# delete wls operator resources
113-
LABEL_SELECTOR="weblogic.operatorName"
114-
#getResWithLabel $tempfile
115-
deleteResWithLabel $tempfile
112+
if [ $total -gt 0 ]; then
113+
echo "Warning: after waiting 300 seconds, there are still $total running pods with label $LABEL_SELECTOR."
114+
fi
116115
}
117116

118-
#
119-
# deleteVoyagerController
120-
#
121117
function deleteVoyagerController {
118+
122119
curl -fsSL https://raw.githubusercontent.com/appscode/voyager/6.0.0/hack/deploy/voyager.sh \
123120
| bash -s -- --provider=baremetal --namespace=voyager --uninstall --purge
121+
kubectl delete namespace voyager
124122
}
125123

124+
#
125+
# deleteNamespaces outputfile
126+
#
127+
function deleteNamespaces {
128+
cat $1 | awk '{ print $4 }' | grep -v "^$" | sort -u | while read line; do
129+
if [ "$line" != "default" ]; then
130+
kubectl delete namespace $line --ignore-not-found
131+
fi
132+
done
133+
134+
}
126135
echo @@ Starting cleanup.
127136
script="${BASH_SOURCE[0]}"
128137
scriptDir="$( cd "$(dirname "${script}")" > /dev/null 2>&1 ; pwd -P)"
@@ -132,16 +141,37 @@ echo "@@ RESULT_ROOT=$RESULT_ROOT TMP_DIR=$TMP_DIR RESULT_DIR=$RESULT_DIR PROJEC
132141
mkdir -p $TMP_DIR || fail No permision to create directory $TMP_DIR
133142

134143
NAMESPACED_TYPES="pod,job,deploy,rs,service,pvc,ingress,cm,serviceaccount,role,rolebinding,secret"
144+
145+
HANDLE_VOYAGER="false"
146+
VOYAGER_ING_NAME="ingresses.voyager.appscode.com"
147+
if [ `kubectl get crd $VOYAGER_ING_NAME --ignore-not-found | grep $VOYAGER_ING_NAME | wc -l` = 1 ]; then
148+
NAMESPACED_TYPES="$VOYAGER_ING_NAME,$NAMESPACED_TYPES"
149+
HANDLE_VOYAGER="true"
150+
fi
151+
152+
DOMAIN_CRD="domains.weblogic.oracle"
153+
if [ `kubectl get crd $DOMAIN_CRD --ignore-not-found | grep $DOMAIN_CRD | wc -l` = 1 ]; then
154+
NAMESPACED_TYPES="$DOMAIN_CRD,$NAMESPACED_TYPES"
155+
fi
156+
135157
NOT_NAMESPACED_TYPES="pv,crd,clusterroles,clusterrolebindings"
136158

137-
# Delele domain resources.
138-
${scriptDir}/../../../kubernetes/delete-weblogic-domain-resources.sh -d all
159+
tempfile="/tmp/$(basename $0).tmp.$$" # == /tmp/[script-file-name].tmp.[pid]
160+
161+
echo @@ Deleting domain resources.
162+
LABEL_SELECTOR="weblogic.domainUID"
163+
deleteResWithLabel "$tempfile-0"
164+
deleteNamespaces "$tempfile-0"
139165

140-
# Delete wls operator
141-
deleteWLSOperators
166+
echo @@ Deleting wls operator resources.
167+
LABEL_SELECTOR="weblogic.operatorName"
168+
deleteResWithLabel "$tempfile-1"
169+
deleteNamespaces "$tempfile-1"
142170

143-
# Delete voyager controller
144-
deleteVoyagerController
171+
echo @@ Deleting voyager controller.
172+
if [ "$HANDLE_VOYAGER" = "true" ]; then
173+
deleteVoyagerController
174+
fi
145175

146176
# Delete pv directories using a job (/scratch maps to PV_ROOT on the k8s cluster machines).
147177

0 commit comments

Comments
 (0)