diff --git a/pkg/cri/server/container_remove.go b/pkg/cri/server/container_remove.go index 926c92fc787d..a7f6f331ae81 100644 --- a/pkg/cri/server/container_remove.go +++ b/pkg/cri/server/container_remove.go @@ -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) diff --git a/pkg/cri/server/container_stop.go b/pkg/cri/server/container_stop.go index a8c9a8702265..d881cb25724a 100644 --- a/pkg/cri/server/container_stop.go +++ b/pkg/cri/server/container_stop.go @@ -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) } } diff --git a/snapshots/devbox/devbox.go b/snapshots/devbox/devbox.go index 38e96bd9e778..9ad840f252e4 100644 --- a/snapshots/devbox/devbox.go +++ b/snapshots/devbox/devbox.go @@ -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. @@ -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 { diff --git a/snapshots/devbox/storage/bolt.go b/snapshots/devbox/storage/bolt.go index 86652860b505..226f6f723adc 100644 --- a/snapshots/devbox/storage/bolt.go +++ b/snapshots/devbox/storage/bolt.go @@ -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" @@ -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") } @@ -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