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
5 changes: 5 additions & 0 deletions pkg/cri/server/container_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveConta
// so we don't need the "Dead" state for now.

// Delete containerd container.
log.G(ctx).WithFields(logrus.Fields{
"container_id": id,
"snapshot_key": i.SnapshotKey,
"snapshotter": i.Snapshotter,
}).Warnf("[CONTAINER-REMOVE-TRACE] About to call container.Container.Delete with WithSnapshotCleanup")
if err := container.Container.Delete(ctx, containerd.WithSnapshotCleanup); err != nil {
if !errdefs.IsNotFound(err) {
return nil, fmt.Errorf("failed to delete containerd container %q: %w", id, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cri/server/container_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ func (c *criService) StopContainer(ctx context.Context, r *runtime.StopContainer

snapshotter := c.runtimeSnapshotter(ctx, ociRuntime)

fmt.Println("Check snapshotter:", snapshotter)
log.G(ctx).Infof("Check snapshotter: %s", snapshotter)

// Check if the snapshotter is devbox and update the devbox snapshot
if snapshotter == "devbox" {
err = c.client.UpdateDevboxSnapshot(ctx, snapshotter, i.ID, unmountLvm, "true")
if err != nil {
fmt.Println("Failed to update devbox snapshot:", err)
log.G(ctx).WithError(err).Errorf("Failed to update devbox snapshot: %s", err)
}
}

Expand Down
17 changes: 15 additions & 2 deletions snapshots/devbox/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ func (o *Snapshotter) Remove(ctx context.Context, key string) (err error) {
removedLvNames []string
)

log.G(ctx).Infof("Remove called with key: %s", key)
log.G(ctx).WithFields(logrus.Fields{
"key": key,
"snapshotter": "devbox",
}).Warnf("[DEVBOX-REMOVE-TRACE] ========== Remove function called ==========")
// Remove directories after the transaction is closed, failures must not
// return error since the transaction is committed with the removal
// key no longer available.
Expand All @@ -421,14 +424,24 @@ func (o *Snapshotter) Remove(ctx context.Context, key string) (err error) {
// modified by sealos
var mountPath string
mountPath, err = storage.RemoveDevbox(ctx, key)
log.G(ctx).Infof("Removed devbox content for key: %s, mount path: %s", key, mountPath)
log.G(ctx).WithFields(logrus.Fields{
"key": key,
"mountPath": mountPath,
"error": err,
}).Warnf("[DEVBOX-REMOVE-TRACE] RemoveDevbox returned")
if err != nil && err != errdefs.ErrNotFound {
return fmt.Errorf("failed to remove devbox content for snapshot %s: %w", key, err)
}
if mountPath != "" {
log.G(ctx).WithFields(logrus.Fields{
"key": key,
"mountPath": mountPath,
}).Warnf("[DEVBOX-REMOVE-TRACE] mountPath is NOT empty, calling unmountLvm")
if err = o.unmountLvm(ctx, mountPath); err != nil {
log.G(ctx).WithError(err).WithField("path", mountPath).Warn("failed to unmount directory")
}
} else {
log.G(ctx).WithField("key", key).Warnf("[DEVBOX-REMOVE-TRACE] mountPath is EMPTY! unmountLvm will NOT be called")
}
_, _, err = storage.Remove(ctx, key)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions snapshots/devbox/storage/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/filters"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/metadata/boltutil"
"github.com/containerd/containerd/snapshots"
bolt "go.etcd.io/bbolt"
Expand Down Expand Up @@ -861,6 +862,8 @@ func RemoveDevbox(ctx context.Context, Key string) (string, error) {
var (
mountPath string
)

log.G(ctx).WithField("key", Key).Warnf("[REMOVE-DEVBOX-TRACE] RemoveDevbox called with key")
if Key == "" {
return "", fmt.Errorf("content key cannot be empty")
}
Expand All @@ -871,10 +874,18 @@ func RemoveDevbox(ctx context.Context, Key string) (string, error) {
}
sbkt := bkt.Bucket([]byte(Key))
if sbkt == nil {
log.G(ctx).WithField("key", Key).Warnf("[REMOVE-DEVBOX-TRACE] devbox snapshot bucket for key %s does not exist", Key)
return errdefs.ErrNotFound
}
contentID := sbkt.Get(DevboxKeyContentID)
mountPath = string(sbkt.Get(DevboxKeyPath))

log.G(ctx).WithFields(log.Fields{
"key": Key,
"contentID": string(contentID),
"mountPath": mountPath,
"mountPath_empty": mountPath == "",
}).Warnf("[REMOVE-DEVBOX-TRACE] Retrieved fields from snapshot bucket")
if len(contentID) == 0 {
// fmt.Printf("content ID for key %s is empty, continuing with snapshotter removal\n", Key)
return nil // if contentID is nil, continue with the snapshotter removal
Expand Down