Skip to content

Commit

Permalink
Ignore missing config.v2.json files on migration
Browse files Browse the repository at this point in the history
We have seen some cases in which the file
`/var/lib/docker/containers/<UUID>/config.v2.json` was not found for
certain UUIDs. This causes the whole migration to fail and, worse,
causes our migration cleanup code to fail.

A missing `config.v2.json` indicates that directory does not contain a
valid container, so we should not even try to migrate them. That's what
this commit does: it makes the migration ignore directories with a
missing `config.v2.json`.

I don't think we should have directories like this in the first place,
this is probably the side effect of some other issue. That said, Docker
itself ignores these directories (after logging a warning) during
startup, so here are just bringing the Engine in line with the standard
behavior.

Signed-off-by: Leandro Motta Barros <[email protected]>
Change-type: patch
  • Loading branch information
lmbarros authored and zoobot committed Nov 21, 2022
1 parent 9b3dce5 commit 5d01bf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/storagemigration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,14 @@ func SwitchAllContainersStorageDriver(root, newStorageDriver string) error {
logrus.Debugf("migrating %v container(s) to %s", len(containerIDs), newStorageDriver)
for _, containerID := range containerIDs {
err := switchContainerStorageDriver(root, containerID, newStorageDriver)
if err != nil {
switch err {
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")
default:
return fmt.Errorf("Error rewriting container config for %s: %v", containerID, err)
}
logrus.WithField("container_id", containerID).Debugf("reconfigured storage-driver to %s", newStorageDriver)
}
return nil
}
7 changes: 7 additions & 0 deletions pkg/storagemigration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package storagemigration

import (
"encoding/json"
"errors"
"os"
"path/filepath"

Expand All @@ -11,6 +12,8 @@ import (
"golang.org/x/sys/unix"
)

var errNoConfigV2JSON = errors.New("config.v2.json not found for container")

// exists checks if a file (or if isDir is set to "true" a directory) exists
func exists(path string, isDir bool) (bool, error) {
fi, err := os.Stat(path)
Expand Down Expand Up @@ -60,6 +63,10 @@ func replicate(sourceDir, targetDir string) error {
// this is the only change needed to make it work after the migration
func switchContainerStorageDriver(root, containerID, newStorageDriver string) error {
containerConfigPath := filepath.Join(root, "containers", containerID, "config.v2.json")
if ok, _ := exists(containerConfigPath, false); !ok {
return errNoConfigV2JSON
}

f, err := os.OpenFile(containerConfigPath, os.O_RDWR, os.ModePerm)
if err != nil {
return err
Expand Down

0 comments on commit 5d01bf7

Please sign in to comment.