Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions cmd/crio/wipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ func crioWipe(c *cli.Context) error {
return err
}

// first, check whether crio has shutdown with time to sync
// if not, we should clear the storage directory
if config.CleanShutdownFile != "" {
// First, check if the node was rebooted.
// We know this happened because the VersionFile (which lives in a tmpfs)
// will not be there.
shouldWipeContainers, err := version.ShouldCrioWipe(config.VersionFile)
if err != nil {
logrus.Infof("checking whether cri-o should wipe containers: %v", err)
}

// Then, check whether crio has shutdown with time to sync.
// Note: this is only needed if the node rebooted.
// If there wasn't time to sync, we should clear the storage directory
if shouldWipeContainers && config.CleanShutdownFile != "" {
if _, err := os.Stat(config.CleanShutdownFile); err != nil {
logrus.Infof("file %s not found. Wiping storage directory %s because of suspected dirty shutdown", config.CleanShutdownFile, store.GraphRoot())
// If we do not do this, we may leak other resources that are not directly in the graphroot.
Expand All @@ -60,16 +69,11 @@ func crioWipe(c *cli.Context) error {
}

shouldWipeImages := true
shouldWipeContainers := true
// First, check if we need to upgrade at all
if !c.IsSet("force") {
// there are two locations we check before wiping:
// one in a temporary directory. This is to check whether the node has rebooted.
// if so, we should remove containers
shouldWipeContainers, err = version.ShouldCrioWipe(config.VersionFile)
if err != nil {
logrus.Infof("%v: triggering wipe of containers", err.Error())
}
// another is needed in a persistent directory. This is to check whether we've upgraded
// if we've upgraded, we should wipe images
shouldWipeImages, err = version.ShouldCrioWipe(config.VersionFilePersist)
Expand Down
29 changes: 15 additions & 14 deletions test/crio-wipe.bats
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,12 @@ function start_crio_with_stopped_pod() {
run_podman_with_args ps -a | grep test
}

@test "don't clear everything when not asked to check shutdown" {
start_crio_with_stopped_pod
stop_crio_no_clean

rm "$CONTAINER_CLEAN_SHUTDOWN_FILE"

CONTAINER_CLEAN_SHUTDOWN_FILE="" run_crio_wipe

start_crio_no_setup

test_crio_did_not_wipe_containers
test_crio_did_not_wipe_images
}

@test "do clear everything when shutdown file not found" {
start_crio_with_stopped_pod
stop_crio_no_clean

rm "$CONTAINER_CLEAN_SHUTDOWN_FILE"
rm "$CONTAINER_VERSION_FILE"

run_crio_wipe

Expand All @@ -158,6 +145,7 @@ function start_crio_with_stopped_pod() {
run_podman_with_args stop -a

rm "$CONTAINER_CLEAN_SHUTDOWN_FILE"
rm "$CONTAINER_VERSION_FILE"

run_crio_wipe

Expand All @@ -177,9 +165,22 @@ function start_crio_with_stopped_pod() {
run_podman_with_args run --name test -d quay.io/crio/busybox:latest top

rm "$CONTAINER_CLEAN_SHUTDOWN_FILE"
rm "$CONTAINER_VERSION_FILE"

run "$CRIO_BINARY_PATH" --config "$CRIO_CONFIG" wipe
echo "$status"
echo "$output"
[ "$status" -ne 0 ]
}

@test "don't clear containers on a forced restart of crio" {
start_crio_with_stopped_pod
stop_crio_no_clean "-9" || true

run_crio_wipe

start_crio_no_setup

test_crio_did_not_wipe_containers
test_crio_did_not_wipe_images
}
5 changes: 3 additions & 2 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,17 @@ function cleanup_pods() {
}

function stop_crio_no_clean() {
local signal="$1"
if [ -n "${CRIO_PID+x}" ]; then
kill "$CRIO_PID" >/dev/null 2>&1
kill "$signal" "$CRIO_PID" >/dev/null 2>&1 || true
wait "$CRIO_PID"
unset CRIO_PID
fi
}

# Stop crio.
function stop_crio() {
stop_crio_no_clean
stop_crio_no_clean ""
cleanup_network_conf
}

Expand Down