Skip to content

Commit e9166e0

Browse files
authored
force trigger mongodb restart (#2564)
wait for mongodb pod to terminate when scale it down reset replicas to 1 if it is already scaled down Signed-off-by: Allen Li <liyuchen223@gmail.com>
1 parent 771a099 commit e9166e0

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

preload_data.sh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function main() {
7474
copy_resource "secret" "mongodb-root-ca-cert"
7575
copy_resource "secret" "icp-mongodb-admin"
7676
#any extra config
77+
success "Preload data from $FROM_NAMESPACE to $TO_NAMESPACE completed successfully."
7778
else
7879
info "Cleanup selected. Cleaning MongoDB in services namespace $TO_NAMESPACE"
7980
cleanup
@@ -336,10 +337,18 @@ function patch_cm() {
336337

337338

338339
migration=$(${OC} get statefulset icp-mongodb -n $FROM_NAMESPACE -o=jsonpath='{.spec.template.metadata.labels.migrating}')
339-
if [[ $migration != "" ]]; then
340-
# scale down icp-mongodb statefulset
341-
${OC} scale statefulSet -n ${FROM_NAMESPACE} icp-mongodb --replicas=0
342-
fi
340+
341+
# scale down icp-mongodb statefulset
342+
# and wait for it to terminate
343+
${OC} scale statefulSet -n ${FROM_NAMESPACE} icp-mongodb --replicas=0
344+
mongodb_pod_count="3"
345+
while [[ "$mongodb_pod_count" -ne "0" ]]
346+
do
347+
info "Waiting for MongoDB pod to terminate"
348+
${OC} get statefulset icp-mongodb -n ${FROM_NAMESPACE}
349+
mongodb_pod_count=$(${OC} get pods -n ${FROM_NAMESPACE} -l app=icp-mongodb --no-headers | wc -l)
350+
sleep 10
351+
done
343352

344353
# update icp-mongodb-init configmap
345354
cat << EOF | ${OC} apply -n $FROM_NAMESPACE -f -
@@ -705,13 +714,18 @@ EOF
705714

706715

707716
# trigger a rolling upgrade
708-
if [[ $migration != "" ]]; then
709-
# scale down icp-mongodb statefulset
710-
${OC} scale statefulSet -n ${FROM_NAMESPACE} icp-mongodb --replicas=${replicas}
711-
else
717+
if [[ $migration == "" ]]; then
712718
${OC} patch statefulSet icp-mongodb -n ${FROM_NAMESPACE} -p '{"spec":{"template":{"metadata":{"labels":{"migrating": "'true'"}}}}}'
713719
fi
714720

721+
# make sure icp-mongodb pod is running
722+
if [[ "$replicas" -eq 0 ]]; then
723+
replicas=1
724+
fi
725+
726+
# scale up icp-mongodb statefulset
727+
${OC} scale statefulSet -n ${FROM_NAMESPACE} icp-mongodb --replicas=${replicas}
728+
715729
# wait for mongodb statefulSet ready
716730
readyReplicas="0"
717731
while [[ "$replicas" != "$readyReplicas" ]]

0 commit comments

Comments
 (0)