@@ -20,7 +20,9 @@ import (
2020 "context"
2121
2222 "github.com/containerd/containerd/containers"
23+ "github.com/containerd/containerd/defaults"
2324 "github.com/containerd/containerd/errdefs"
25+ "github.com/containerd/containerd/namespaces"
2426 "github.com/containerd/containerd/oci"
2527 "github.com/containerd/containerd/platforms"
2628 "github.com/containerd/containerd/snapshots"
@@ -107,7 +109,7 @@ func WithSnapshotter(name string) NewContainerOpts {
107109// WithSnapshot uses an existing root filesystem for the container
108110func WithSnapshot (id string ) NewContainerOpts {
109111 return func (ctx context.Context , client * Client , c * containers.Container ) error {
110- setSnapshotterIfEmpty (c )
112+ setSnapshotterIfEmpty (ctx , client , c )
111113 // check that the snapshot exists, if not, fail on creation
112114 if _ , err := client .SnapshotService (c .Snapshotter ).Mounts (ctx , id ); err != nil {
113115 return err
@@ -125,7 +127,7 @@ func WithNewSnapshot(id string, i Image, opts ...snapshots.Opt) NewContainerOpts
125127 if err != nil {
126128 return err
127129 }
128- setSnapshotterIfEmpty (c )
130+ setSnapshotterIfEmpty (ctx , client , c )
129131 parent := identity .ChainID (diffIDs ).String ()
130132 if _ , err := client .SnapshotService (c .Snapshotter ).Prepare (ctx , id , parent , opts ... ); err != nil {
131133 return err
@@ -155,7 +157,7 @@ func WithNewSnapshotView(id string, i Image, opts ...snapshots.Opt) NewContainer
155157 if err != nil {
156158 return err
157159 }
158- setSnapshotterIfEmpty (c )
160+ setSnapshotterIfEmpty (ctx , client , c )
159161 parent := identity .ChainID (diffIDs ).String ()
160162 if _ , err := client .SnapshotService (c .Snapshotter ).View (ctx , id , parent , opts ... ); err != nil {
161163 return err
@@ -166,9 +168,18 @@ func WithNewSnapshotView(id string, i Image, opts ...snapshots.Opt) NewContainer
166168 }
167169}
168170
169- func setSnapshotterIfEmpty (c * containers.Container ) {
171+ func setSnapshotterIfEmpty (ctx context. Context , client * Client , c * containers.Container ) {
170172 if c .Snapshotter == "" {
171- c .Snapshotter = DefaultSnapshotter
173+ defaultSnapshotter := DefaultSnapshotter
174+ namespaceService := client .NamespaceService ()
175+ if ns , err := namespaces .NamespaceRequired (ctx ); err == nil {
176+ if labels , err := namespaceService .Labels (ctx , ns ); err == nil {
177+ if snapshotLabel , ok := labels [defaults .DefaultSnapshotterNSLabel ]; ok {
178+ defaultSnapshotter = snapshotLabel
179+ }
180+ }
181+ }
182+ c .Snapshotter = defaultSnapshotter
172183 }
173184}
174185
0 commit comments