Skip to content
Open
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
11 changes: 10 additions & 1 deletion cmd/containerd-stargz-grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ func main() {
if !managerNewlyStarted {
flags = append(flags, snbase.NoRestore)
}
imageServicePath := config.ImageServicePath
if imageServicePath == "" {
imageServicePath = defaultImageServiceAddress
}
flags = append(flags, snbase.CleanupOrphanRemoteSnapshotsOnStartup(imageServicePath))
rs, err = snbase.NewSnapshotter(ctx, filepath.Join(*rootDir, "snapshotter"), fs, flags...)
if err != nil {
log.G(ctx).WithError(err).Fatalf("failed to configure snapshotter")
Expand Down Expand Up @@ -253,7 +258,11 @@ func main() {
log.G(ctx).WithError(err).Fatalf("failed to configure fs config")
}

rs, err = service.NewStargzSnapshotterService(ctx, *rootDir, &config.Config,
serviceConfig := config.Config
if serviceConfig.ImageServicePath == "" {
serviceConfig.ImageServicePath = defaultImageServiceAddress
}
rs, err = service.NewStargzSnapshotterService(ctx, *rootDir, &serviceConfig,
service.WithCredsFuncs(credsFuncs...), service.WithFilesystemOptions(fsOpts...))
if err != nil {
log.G(ctx).WithError(err).Fatalf("failed to configure snapshotter")
Expand Down
4 changes: 4 additions & 0 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ func (fs *filesystem) Unmount(ctx context.Context, mountpoint string) error {
return nil
}

func (fs *filesystem) Cleanup(ctx context.Context) error {
return fs.resolver.Cleanup(ctx)
}

func unmount(target string, flags int) error {
for {
if err := unix.Unmount(target, flags); err != unix.EINTR {
Expand Down
15 changes: 15 additions & 0 deletions fs/layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package layer
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -196,6 +197,20 @@ func NewResolver(root string, backgroundTaskManager *task.BackgroundTaskManager,
}, nil
}

func (r *Resolver) Cleanup(ctx context.Context) error {
var errs []error
for _, dir := range []string{
filepath.Join(r.rootDir, "fscache"),
filepath.Join(r.rootDir, "httpcache"),
} {
if err := os.RemoveAll(dir); err != nil {
log.G(ctx).WithError(err).WithField("dir", dir).Warn("failed to cleanup cache directory")
errs = append(errs, err)
}
}
return errors.Join(errs...)
}

func newCache(root string, cacheType string, cfg config.Config) (cache.BlobCache, error) {
if cacheType == memoryCacheType {
return cache.NewMemoryCache(), nil
Expand Down
3 changes: 3 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func NewStargzSnapshotterService(ctx context.Context, root string, config *Confi
if config.AllowInvalidMountsOnRestart {
snOpts = append(snOpts, snapshot.AllowInvalidMountsOnRestart)
}
if config.ImageServicePath != "" {
snOpts = append(snOpts, snapshot.CleanupOrphanRemoteSnapshotsOnStartup(config.ImageServicePath))
}

snapshotter, err = snapshot.NewSnapshotter(ctx, snapshotterRoot(root), fs, snOpts...)
if err != nil {
Expand Down
Loading
Loading