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

Skip to content

Commit 25235eb

Browse files
committed
return error when snapshotter can't be resolved
1 parent 3551ac8 commit 25235eb

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

explorers/containerd/containerd.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,27 +451,26 @@ func (e *explorer) InfoContainer(ctx context.Context, containerid string, spec b
451451

452452
// resolveSnapshotter checks the snapshotter in meta.db.
453453
// If not found, falls back to "overlayfs".
454-
func (e *explorer) resolveSnapshotter(ctx context.Context, container *containers.Container) {
454+
func (e *explorer) resolveSnapshotter(ctx context.Context, container *containers.Container) error {
455455
if container.Snapshotter != "" && container.SnapshotKey != "" {
456-
return
456+
return nil
457457
}
458458

459459
namespace, err := namespaces.NamespaceRequired(ctx)
460460
if err != nil {
461-
log.Warnf("failed to get namespace from context when resolving snapshotter: %v", err)
462461
if container.Snapshotter == "" {
463462
container.Snapshotter = "overlayfs" // default fallback
464463
}
465464
if container.SnapshotKey == "" {
466465
container.SnapshotKey = container.ID
467466
}
468-
return
467+
return fmt.Errorf("failed to get namespace from context when resolving snapshotter: %w", err)
469468
}
470469

471470
var foundSnapshotter string
472471
var foundSnapshotKey string
473472

474-
_ = e.mdb.View(func(tx *bolt.Tx) error {
473+
dbErr := e.mdb.View(func(tx *bolt.Tx) error {
475474
bkt := getSnapshottersBucket(tx, namespace)
476475
if bkt == nil {
477476
return nil
@@ -530,6 +529,10 @@ func (e *explorer) resolveSnapshotter(ctx context.Context, container *containers
530529
return nil
531530
})
532531

532+
if dbErr != nil && dbErr.Error() != "found" {
533+
return fmt.Errorf("failed to view database: %w", dbErr)
534+
}
535+
533536
if foundSnapshotter != "" {
534537
container.Snapshotter = foundSnapshotter
535538
container.SnapshotKey = foundSnapshotKey
@@ -543,6 +546,7 @@ func (e *explorer) resolveSnapshotter(ctx context.Context, container *containers
543546
}
544547
log.Warnf("could not resolve snapshotter/key in meta.db for container %s, falling back to snapshotter=%s, key=%s", container.ID, container.Snapshotter, container.SnapshotKey)
545548
}
549+
return nil
546550
}
547551

548552
// MountContainer mounts a container to the specified path
@@ -554,7 +558,9 @@ func (e *explorer) MountContainer(ctx context.Context, containerid string, mount
554558
return fmt.Errorf("failed getting container information %v", err)
555559
}
556560

557-
e.resolveSnapshotter(ctx, &container)
561+
if err := e.resolveSnapshotter(ctx, &container); err != nil {
562+
return fmt.Errorf("failed to resolve snapshotter: %w", err)
563+
}
558564

559565
// Snapshot database metadata.db access
560566
opts := bolt.Options{
@@ -826,7 +832,9 @@ func (e *explorer) ContainerDrift(ctx context.Context, filter string, skipsuppor
826832
if err != nil {
827833
return nil, fmt.Errorf("failed getting container information %v", err)
828834
}
829-
e.resolveSnapshotter(ctx, &container)
835+
if err := e.resolveSnapshotter(ctx, &container); err != nil {
836+
return nil, fmt.Errorf("failed to resolve snapshotter: %w", err)
837+
}
830838
// Snapshot database metadata.db access
831839
opts := bolt.Options{
832840
ReadOnly: true,

0 commit comments

Comments
 (0)