@@ -78,6 +78,7 @@ function getResWithLabel {
78
78
# deleteResWithLabel outputfile
79
79
#
80
80
function deleteResWithLabel {
81
+ echo @@ Delete resources with label $LABEL_SELECTOR .
81
82
# clean the output file first
82
83
if [ -e $1 ]; then
83
84
rm $1
@@ -86,43 +87,51 @@ function deleteResWithLabel {
86
87
getResWithLabel $1
87
88
# delete namespaced types
88
89
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 "
94
91
done
95
92
96
93
# delete non-namespaced types
97
94
local no_namespace_count=` grep -c -v " -n " $1 `
98
95
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
101
106
else
102
- kubectl delete $NOT_NAMESPACED_TYPES -l " $LABEL_SELECTOR "
107
+ echo " @@ There are still $total running pods with label $LABEL_SELECTOR . "
103
108
fi
104
- fi
105
- }
109
+ sleep 3
110
+ done
106
111
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
116
115
}
117
116
118
- #
119
- # deleteVoyagerController
120
- #
121
117
function deleteVoyagerController {
118
+
122
119
curl -fsSL https://raw.githubusercontent.com/appscode/voyager/6.0.0/hack/deploy/voyager.sh \
123
120
| bash -s -- --provider=baremetal --namespace=voyager --uninstall --purge
121
+ kubectl delete namespace voyager
124
122
}
125
123
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
+ }
126
135
echo @@ Starting cleanup.
127
136
script=" ${BASH_SOURCE[0]} "
128
137
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
132
141
mkdir -p $TMP_DIR || fail No permision to create directory $TMP_DIR
133
142
134
143
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
+
135
157
NOT_NAMESPACED_TYPES=" pv,crd,clusterroles,clusterrolebindings"
136
158
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"
139
165
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"
142
170
143
- # Delete voyager controller
144
- deleteVoyagerController
171
+ echo @@ Deleting voyager controller.
172
+ if [ " $HANDLE_VOYAGER " = " true" ]; then
173
+ deleteVoyagerController
174
+ fi
145
175
146
176
# Delete pv directories using a job (/scratch maps to PV_ROOT on the k8s cluster machines).
147
177
0 commit comments