Skip to content

Commit e212cfd

Browse files
Merge pull request #9148 from PannagaRao/crio-wipe-1.30
[release-1.30]: OCPBUGS-55241: crio wipe should remove storage only once per reboot
2 parents 97e6ff8 + 56974eb commit e212cfd

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

internal/criocli/wipe.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package criocli
22

33
import (
44
"errors"
5+
"fmt"
56
"os"
67

78
cstorage "github.com/containers/storage"
@@ -68,8 +69,22 @@ func crioWipe(c *cli.Context) error {
6869
config.CleanShutdownFile,
6970
store.GraphRoot(),
7071
)
72+
73+
const wipeMarkerFile = "/run/crio/crio-wipe-done"
74+
if _, err := os.Stat(wipeMarkerFile); err == nil {
75+
logrus.Infof("Unclean shutdown check already succeeded by previous crio wipe command")
76+
77+
return nil
78+
}
79+
7180
// This will fail if there are any containers currently running.
72-
return lib.RemoveStorageDirectory(config, store, false)
81+
if err := lib.RemoveStorageDirectory(config, store, false); err != nil {
82+
return fmt.Errorf("failed to remove storage directory %w", err)
83+
}
84+
85+
if err = os.WriteFile(wipeMarkerFile, []byte("done"), 0o644); err != nil {
86+
logrus.Warnf("Failed to create crio wipe marker file: %v", err)
87+
}
7388
}
7489

7590
// If crio is configured to wipe internally (and `--force` wasn't set)

test/crio-wipe.bats

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ function start_crio_with_stopped_pod() {
8585

8686
rm "$CONTAINER_VERSION_FILE"
8787
rm "$CONTAINER_VERSION_FILE_PERSIST"
88+
rm -f "/run/crio/crio-wipe-done"
8889
run_crio_wipe
8990

9091
CONTAINER_INTERNAL_WIPE=false start_crio_no_setup
@@ -97,6 +98,7 @@ function start_crio_with_stopped_pod() {
9798
stop_crio_no_clean
9899

99100
rm "$CONTAINER_VERSION_FILE"
101+
rm -f "/run/crio/crio-wipe-done"
100102
run_crio_wipe
101103

102104
CONTAINER_INTERNAL_WIPE=false start_crio_no_setup
@@ -109,6 +111,7 @@ function start_crio_with_stopped_pod() {
109111
stop_crio_no_clean
110112

111113
rm "$CONTAINER_VERSION_FILE_PERSIST"
114+
rm -f "/run/crio/crio-wipe-done"
112115
run_crio_wipe
113116

114117
CONTAINER_INTERNAL_WIPE=false start_crio_no_setup
@@ -123,6 +126,7 @@ function start_crio_with_stopped_pod() {
123126

124127
CONTAINER_INTERNAL_WIPE=false start_crio_with_stopped_pod
125128
stop_crio_no_clean
129+
rm -f "/run/crio/crio-wipe-done"
126130

127131
run_podman_with_args run --name test -d quay.io/crio/fedora-crio-ci:latest top
128132

@@ -137,6 +141,7 @@ function start_crio_with_stopped_pod() {
137141

138142
rm "$CONTAINER_CLEAN_SHUTDOWN_FILE"
139143
rm "$CONTAINER_VERSION_FILE"
144+
rm -f "/run/crio/crio-wipe-done"
140145

141146
run_crio_wipe
142147

@@ -160,6 +165,7 @@ function start_crio_with_stopped_pod() {
160165

161166
rm "$CONTAINER_CLEAN_SHUTDOWN_FILE"
162167
rm "$CONTAINER_VERSION_FILE"
168+
rm -f "/run/crio/crio-wipe-done"
163169

164170
run_crio_wipe
165171

@@ -179,6 +185,7 @@ function start_crio_with_stopped_pod() {
179185

180186
rm "$CONTAINER_CLEAN_SHUTDOWN_FILE"
181187
rm "$CONTAINER_VERSION_FILE"
188+
rm -f "/run/crio/crio-wipe-done"
182189

183190
run ! "$CRIO_BINARY_PATH" --config "$CRIO_CONFIG" -d "$CRIO_CONFIG_DIR" wipe
184191
}
@@ -187,6 +194,7 @@ function start_crio_with_stopped_pod() {
187194
CONTAINER_INTERNAL_WIPE=false start_crio_with_stopped_pod
188195
stop_crio_no_clean "-9" || true
189196

197+
rm -f "/run/crio/crio-wipe-done"
190198
run_crio_wipe
191199

192200
CONTAINER_INTERNAL_WIPE=false start_crio_no_setup
@@ -201,6 +209,7 @@ function start_crio_with_stopped_pod() {
201209

202210
rm "$CONTAINER_CLEAN_SHUTDOWN_FILE.supported"
203211

212+
rm -f "/run/crio/crio-wipe-done"
204213
run_crio_wipe
205214

206215
CONTAINER_INTERNAL_WIPE=false start_crio_no_setup
@@ -376,3 +385,24 @@ function start_crio_with_stopped_pod() {
376385
return 1
377386
fi
378387
}
388+
389+
@test "crio-wipe should create /run/crio/crio-wipe-done and not wipe again" {
390+
CONTAINER_INTERNAL_WIPE=false start_crio_with_stopped_pod
391+
stop_crio_no_clean
392+
393+
rm "$CONTAINER_CLEAN_SHUTDOWN_FILE"
394+
rm "$CONTAINER_VERSION_FILE"
395+
rm -f "/run/crio/crio-wipe-done"
396+
397+
run_crio_wipe
398+
399+
ls -l /run/crio/crio-wipe-done
400+
401+
run cat /run/crio/crio-wipe-done
402+
[[ "$output" == "done" ]]
403+
404+
run_crio_wipe
405+
[[ ! "$output" == *"Wiping storage directory"* ]]
406+
407+
ls -l /run/crio/crio-wipe-done
408+
}

0 commit comments

Comments
 (0)