diff --git a/cmd/containerd-stargz-grpc/main.go b/cmd/containerd-stargz-grpc/main.go index 531ebefb2..318ce71ad 100644 --- a/cmd/containerd-stargz-grpc/main.go +++ b/cmd/containerd-stargz-grpc/main.go @@ -181,7 +181,7 @@ func main() { if err != nil { log.G(ctx).WithError(err).Fatalf("failed to configure fusemanager") } - rs, err = snbase.NewSnapshotter(ctx, filepath.Join(*rootDir, "snapshotter"), fs, snbase.AsynchronousRemove) + rs, err = snbase.NewSnapshotter(ctx, filepath.Join(*rootDir, "snapshotter"), fs, snbase.AsynchronousRemove, snbase.SetDetachFlag) if err != nil { log.G(ctx).WithError(err).Fatalf("failed to configure snapshotter") } @@ -213,10 +213,6 @@ func main() { log.G(ctx).WithError(err).Fatalf("failed to serve snapshotter") } - // TODO: In detach mode, rs is taken over by fusemanager, - // but client will send unmount request to fusemanager, - // and fusemanager need get mount info from local db to - // determine its behavior if cleanup { log.G(ctx).Debug("Closing the snapshotter") rs.Close() diff --git a/docs/overview.md b/docs/overview.md index 43e42ba2f..597d84f0d 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -118,6 +118,18 @@ When upgrading the fuse manager, it's recommended to follow these steps: This ensures a clean upgrade without impacting running containers. +### Important Considerations + +Before restarting the `containerd-stargz-grpc` process, it is essential to consider the state of any running containers. + +1. **When to Use SIGKILL** : + +If there are running containers, it is crucial to terminate the `containerd-stargz-grpc` process using `SIGKILL`. This approach prevents the normal shutdown sequence from attempting to clean up the mount points of the running containers, which could disrupt their availability. By using `SIGKILL`, you ensure that the process is forcefully terminated without affecting the ongoing operations of the containers. + +2. **When to Use SIGTERM** : + +If there are no running containers, you should use `SIGTERM` to terminate the `containerd-stargz-grpc` process. This allows the process to follow its normal shutdown sequence, ensuring that it properly cleans up resources and mount points. + ## Registry-related configuration You can configure stargz snapshotter for accessing registries with custom configurations. diff --git a/snapshot/snapshot.go b/snapshot/snapshot.go index 4405a38c9..03dbeca07 100644 --- a/snapshot/snapshot.go +++ b/snapshot/snapshot.go @@ -73,6 +73,7 @@ type SnapshotterConfig struct { asyncRemove bool noRestore bool allowInvalidMountsOnRestart bool + detach bool } // Opt is an option to configure the remote snapshotter @@ -97,6 +98,11 @@ func AllowInvalidMountsOnRestart(config *SnapshotterConfig) error { return nil } +func SetDetachFlag(config *SnapshotterConfig) error { + config.detach = true + return nil +} + type snapshotter struct { root string ms *storage.MetaStore @@ -107,6 +113,7 @@ type snapshotter struct { userxattr bool // whether to enable "userxattr" mount option noRestore bool allowInvalidMountsOnRestart bool + detach bool } // NewSnapshotter returns a Snapshotter which can use unpacked remote layers @@ -157,6 +164,7 @@ func NewSnapshotter(ctx context.Context, root string, targetFs FileSystem, opts userxattr: userxattr, noRestore: config.noRestore, allowInvalidMountsOnRestart: config.allowInvalidMountsOnRestart, + detach: config.detach, } if err := o.restoreRemoteSnapshot(ctx); err != nil { @@ -736,6 +744,10 @@ func (o *snapshotter) checkAvailability(ctx context.Context, key string) bool { } func (o *snapshotter) restoreRemoteSnapshot(ctx context.Context) error { + if o.detach { + return nil + } + mounts, err := mountinfo.GetMounts(nil) if err != nil { return err