diff --git a/e2e/main.sh b/e2e/main.sh index 8f32bc7da8..313567863a 100755 --- a/e2e/main.sh +++ b/e2e/main.sh @@ -120,7 +120,7 @@ microshift_debug_info() { microshift_cleanup() { local output_dir="${1}" log "Cleaning MicroShift" - ssh_cmd "echo 1 | sudo microshift-cleanup-data --all" &>"${output_dir}/0000-cleanup.log" + ssh_cmd "echo 1 | sudo microshift-cleanup-data --all --keep-images" &>"${output_dir}/0000-cleanup.log" } microshift_reprovision() { diff --git a/e2e/tests/assets/greenboot-test.sh b/e2e/tests/assets/greenboot-test.sh index ef9c1061be..823f9ff58c 100644 --- a/e2e/tests/assets/greenboot-test.sh +++ b/e2e/tests/assets/greenboot-test.sh @@ -10,7 +10,8 @@ function check_greenboot_exit_status() { local cleanup=$2 if [ "${cleanup}" -ne 0 ]; then - echo 1 | microshift-cleanup-data --all + # Skip image deletion to speed up the test and make it more reliable + echo 1 | microshift-cleanup-data --all --keep-images systemctl enable --now microshift || true fi diff --git a/scripts/microshift-cleanup-data.sh b/scripts/microshift-cleanup-data.sh index 0f160f1489..0399742c7a 100755 --- a/scripts/microshift-cleanup-data.sh +++ b/scripts/microshift-cleanup-data.sh @@ -5,13 +5,15 @@ SCRIPT_NAME=$(basename "$0") # to allow for pod deletion when MicroShift is stopped PODS_NS_LIST=(openshift-service-ca openshift-ingress openshift-dns openshift-storage openshift-ovn-kubernetes) FULL_CLEAN=true +KEEP_IMAGE=false function usage() { echo "Stop all MicroShift services, also cleaning their data" echo "" - echo "Usage: ${SCRIPT_NAME} <--all | --ovn>" - echo " --all Clean all MicroShift and OVN data" - echo " --ovn Clean OVN data only" + echo "Usage: ${SCRIPT_NAME} <--all [--keep-images] | --ovn>" + echo " --all Clean all MicroShift and OVN data" + echo " --keep-images Keep container images when cleaning all data" + echo " --ovn Clean OVN data only" exit 1 } @@ -34,15 +36,16 @@ function stop_disable_services() { } function stop_clean_pods() { - # Wipe the crio data off and return - if ${FULL_CLEAN} ; then + # Wipe all the crio data off and return + if ${FULL_CLEAN} && ! ${KEEP_IMAGE} ; then echo Removing crio container and image storage crio wipe -f &>/dev/null systemctl restart crio return fi - # It is necessary to stop the pods (OVN-related last) to allow for further termination + # Delete pods only, preserving images + # It is necessary to remove the pods (OVN-related last) to allow for further termination # of processes (i.e. conmon, etc.) that use the files under /var/run/ovn. # The cleanup of OVN data only works if the files under /var/run/ovn are not in use. echo Removing MicroShift pods @@ -56,7 +59,8 @@ function stop_clean_pods() { if [ "$(echo "${ocp_pods}" | wc -w)" -eq 0 ] ; then break fi - crictl rmp -f "${ocp_pods}" &>/dev/null + # shellcheck disable=SC2086 + crictl rmp -f ${ocp_pods} &>/dev/null retries=$(( retries - 1 )) done done @@ -97,6 +101,7 @@ function clean_data() { # Parse command line case $1 in --all) + [ "$2" = "--keep-images" ] && KEEP_IMAGE=true ;; --ovn) FULL_CLEAN=false @@ -116,11 +121,11 @@ if ${FULL_CLEAN} ; then echo "DATA LOSS WARNING: Do you wish to stop and clean ALL MicroShift data AND cri-o container workloads?" select yn in "Yes" "No"; do case "${yn}" in - Yes) + Yes) break ;; *) - echo "Aborting cleanup" + echo "Aborting cleanup" exit 0 ;; esac