@@ -348,35 +348,55 @@ wait_restore() {
348348 local ok_if_ready=${6:- 0}
349349
350350 set +o xtrace
351+ # We need to run wait after the resourse is created, othrwise it fails at once
352+ echo -n " Waiting for the psmdb-restore/restore-$backup_name object to be created"
353+ retry_object=0
354+ until [[ ${retry_object} == 60 ]]; do
355+ echo -n .
356+ if kubectl_bin get psmdb-restore restore-$backup_name > /dev/null; then
357+ echo " OK"
358+ break
359+ fi
360+ let retry_object+=1
361+ if [[ ${retry_object} == 60 ]]; then
362+ echo " psmdb-restore/restore-$backup_name object was not created."
363+ exit 1
364+ fi
365+ sleep 1
366+ done
367+
368+ echo -n " Waiting psmdb-restore/restore-${backup_name} to reach state \" ${target_state} \" "
351369 retry=0
352- echo -n " waiting psmdb-restore/restore-${backup_name} to reach ${target_state} state"
353- local current_state=
354- until [[ ${current_state} == ${target_state} ]]; do
355- sleep 0.5
370+ retry_count=$(( wait_time / 60 ))
371+ until [[ ${retry} == ${retry_count} ]]; do
356372 echo -n .
357373 let retry+=1
358- current_state=$( kubectl_bin get psmdb-restore restore-$backup_name -o jsonpath=' {.status.state}' )
359- if [[ ${ok_if_ready} == 1 && ${current_state} == ' ready' ]]; then
374+ if kubectl_bin wait psmdb-restore restore-${backup_name} --for=jsonpath=' {.status.state}' =${target_state} --timeout=60s 2> /dev/null; then
360375 echo " OK"
361376 break
362377 fi
363- if [[ $retry -ge $wait_time || ${current_state} == ' error' ]]; then
364- kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
365- | grep -v ' level=info' \
366- | grep -v ' level=debug' \
367- | grep -v ' Getting tasks for pod' \
368- | grep -v ' Getting pods from source' \
369- | tail -100
370- kubectl_bin get psmdb-restore restore-${backup_name} -o yaml
371- echo " Restore object restore-${backup_name} is in ${current_state} state."
372- echo something went wrong with operator or kubernetes cluster
373- exit 1
378+ current_state=$( kubectl_bin get psmdb-restore restore-$backup_name -o jsonpath=' {.status.state}' )
379+ if [[ ${ok_if_ready} == 1 && ${current_state} == ' ready' ]]; then
380+ echo " OK"
381+ break
382+ fi
383+ if [[ ${retry} == ${retry_count} || ${current_state} == ' error' ]]; then
384+ kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
385+ | grep -v ' level=info' \
386+ | grep -v ' level=debug' \
387+ | grep -v ' Getting tasks for pod' \
388+ | grep -v ' Getting pods from source' \
389+ | tail -100
390+ kubectl_bin get psmdb-restore restore-${backup_name} -o yaml
391+ echo " Restore object restore-${backup_name} is in ${current_state} state."
392+ echo something went wrong with operator or kubernetes cluster
393+ exit 1
374394 fi
375395 done
396+
376397 echo " OK"
377398 set_debug
378-
379- if [ $wait_cluster_consistency -eq 1 ]; then
399+ if [[ $wait_cluster_consistency -eq 1 ]]; then
380400 wait_cluster_consistency " ${cluster_name} "
381401 fi
382402}
0 commit comments