Skip to content

Commit

Permalink
Rollback to ausf and cleanup overlay2 in case of missing config.v2.json
Browse files Browse the repository at this point in the history
Add test for missing config.v2.json

Changelog-entry: Rollback to ausf and cleanup overlay2 in case of missing config.v2.json
Change-type: patch
Signed-off-by: zoobot <[email protected]>
  • Loading branch information
zoobot committed Nov 21, 2022
1 parent 5d01bf7 commit b71b5df
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
23 changes: 18 additions & 5 deletions pkg/storagemigration/failcleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ import (
// FailCleanup should be run after a failed migration.
// It will remove any files left over from the migration process
// and migrate containers back to aufs.
//
func failCleanup(root string) error {
logrus.WithField("storage_root", root).Warning("recovering from failed aufs to overlay migration")

var err error
err = SwitchAllContainersStorageDriver(root, "aufs")
if err != nil {
return fmt.Errorf("Error migrating containers to aufs: %v", err)
}

err = removeDirIfExists(tempTargetRoot(root))
if err != nil {
Expand All @@ -36,5 +31,23 @@ func failCleanup(root string) error {
return err
}

err = SwitchAllContainersStorageDriver(root, "aufs")
if err != nil {
return fmt.Errorf("Error migrating containers to aufs: %v", err)
}

return nil
}

func failCleanupContainer(root string, containerID string) error {
logrus.WithField("containerId", containerID).Warning("recovering from container config missing during aufs to overlay migration")
var err error

containerDir := filepath.Join(root, "containers", containerID)
err = removeDirIfExists(containerDir)
if err != nil {
return err
}

return nil
}
4 changes: 2 additions & 2 deletions pkg/storagemigration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func Migrate(root string) (err error) {
if err != nil {
return fmt.Errorf("Error migrating containers to overlay2: %v", err)
}

return nil
}

Expand Down Expand Up @@ -340,7 +339,8 @@ func SwitchAllContainersStorageDriver(root, newStorageDriver string) error {
case nil:
logrus.WithField("container_id", containerID).Debugf("reconfigured storage-driver to %s", newStorageDriver)
case errNoConfigV2JSON:
logrus.WithField("container_id", containerID).Warning("ignoring container without config.v2.json")
logrus.WithField("container_id", containerID).Errorf("has no config.v2.json %s", newStorageDriver)
return fmt.Errorf("Error containerID %s: %v", containerID, err)
default:
return fmt.Errorf("Error rewriting container config for %s: %v", containerID, err)
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/storagemigration/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func setup(t *testing.T) (*fs.Dir, *State, func()) {
),
),
)

state := &State{
Layers: []Layer{
{
Expand Down Expand Up @@ -132,3 +133,30 @@ func TestFailCleanup(t *testing.T) {
_, err = os.Stat(root.Join("aufs"))
assert.NilError(t, err)
}

func TestFailCleanupContainer(t *testing.T) {
root, _, cleanup := setup(t)
defer cleanup()

// delete config.v2.json to force SwitchAllContainersStorageDriver to fail
os.Remove(root.Join("containers", "bebe92422caf828ab21ae39974a0c003a29970ec09c6e5529bbb24f71eb9ca2ef", "config.v2.json"))

err := Migrate(root.Path())
assert.ErrorContains(t, err, "bebe92422caf828ab21ae39974a0c003a29970ec09c6e5529bbb24f71eb9ca2ef")

// config.v2.json should not exists
_, err = os.Stat(root.Join("containers", "bebe92422caf828ab21ae39974a0c003a29970ec09c6e5529bbb24f71eb9ca2ef", "config.v2.json"))
assert.ErrorType(t, err, os.IsNotExist)

// migration logfile should exists
_, err = os.Stat(root.Join("migrate.log"))
assert.NilError(t, err)

// overlay2 directory should not exists
_, err = os.Stat(root.Join("overlay2"))
assert.ErrorType(t, err, os.IsNotExist)

// aufs directory should still exists
_, err = os.Stat(root.Join("aufs"))
assert.NilError(t, err)
}

0 comments on commit b71b5df

Please sign in to comment.