@@ -20,9 +20,7 @@ import (
2020 "context"
2121
2222 "github.com/containerd/containerd/containers"
23- "github.com/containerd/containerd/defaults"
2423 "github.com/containerd/containerd/errdefs"
25- "github.com/containerd/containerd/namespaces"
2624 "github.com/containerd/containerd/oci"
2725 "github.com/containerd/containerd/platforms"
2826 "github.com/containerd/containerd/snapshots"
@@ -118,9 +116,8 @@ func WithSnapshotter(name string) NewContainerOpts {
118116// WithSnapshot uses an existing root filesystem for the container
119117func WithSnapshot (id string ) NewContainerOpts {
120118 return func (ctx context.Context , client * Client , c * containers.Container ) error {
121- setSnapshotterIfEmpty (ctx , client , c )
122119 // check that the snapshot exists, if not, fail on creation
123- s , err := client .getSnapshotter (c .Snapshotter )
120+ s , err := client .getSnapshotter (ctx , c .Snapshotter )
124121 if err != nil {
125122 return err
126123 }
@@ -140,9 +137,9 @@ func WithNewSnapshot(id string, i Image, opts ...snapshots.Opt) NewContainerOpts
140137 if err != nil {
141138 return err
142139 }
143- setSnapshotterIfEmpty ( ctx , client , c )
140+
144141 parent := identity .ChainID (diffIDs ).String ()
145- s , err := client .getSnapshotter (c .Snapshotter )
142+ s , err := client .getSnapshotter (ctx , c .Snapshotter )
146143 if err != nil {
147144 return err
148145 }
@@ -161,7 +158,7 @@ func WithSnapshotCleanup(ctx context.Context, client *Client, c containers.Conta
161158 if c .Snapshotter == "" {
162159 return errors .Wrapf (errdefs .ErrInvalidArgument , "container.Snapshotter must be set to cleanup rootfs snapshot" )
163160 }
164- s , err := client .getSnapshotter (c .Snapshotter )
161+ s , err := client .getSnapshotter (ctx , c .Snapshotter )
165162 if err != nil {
166163 return err
167164 }
@@ -178,9 +175,9 @@ func WithNewSnapshotView(id string, i Image, opts ...snapshots.Opt) NewContainer
178175 if err != nil {
179176 return err
180177 }
181- setSnapshotterIfEmpty ( ctx , client , c )
178+
182179 parent := identity .ChainID (diffIDs ).String ()
183- s , err := client .getSnapshotter (c .Snapshotter )
180+ s , err := client .getSnapshotter (ctx , c .Snapshotter )
184181 if err != nil {
185182 return err
186183 }
@@ -193,21 +190,6 @@ func WithNewSnapshotView(id string, i Image, opts ...snapshots.Opt) NewContainer
193190 }
194191}
195192
196- func setSnapshotterIfEmpty (ctx context.Context , client * Client , c * containers.Container ) {
197- if c .Snapshotter == "" {
198- defaultSnapshotter := DefaultSnapshotter
199- namespaceService := client .NamespaceService ()
200- if ns , err := namespaces .NamespaceRequired (ctx ); err == nil {
201- if labels , err := namespaceService .Labels (ctx , ns ); err == nil {
202- if snapshotLabel , ok := labels [defaults .DefaultSnapshotterNSLabel ]; ok {
203- defaultSnapshotter = snapshotLabel
204- }
205- }
206- }
207- c .Snapshotter = defaultSnapshotter
208- }
209- }
210-
211193// WithContainerExtension appends extension data to the container object.
212194// Use this to decorate the container object with additional data for the client
213195// integration.
0 commit comments