Skip to content

Commit 1918ee4

Browse files
committed
Respect default snapshotter label
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent 47d2ac0 commit 1918ee4

6 files changed

Lines changed: 17 additions & 34 deletions

File tree

client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ func defaultRemoteContext() *RemoteContext {
332332
Resolver: docker.NewResolver(docker.ResolverOptions{
333333
Client: http.DefaultClient,
334334
}),
335-
Snapshotter: DefaultSnapshotter,
336335
}
337336
}
338337

@@ -672,7 +671,13 @@ func (c *Client) Version(ctx context.Context) (Version, error) {
672671
}, nil
673672
}
674673

675-
func (c *Client) getSnapshotter(name string) (snapshots.Snapshotter, error) {
674+
func (c *Client) getSnapshotter(ctx context.Context, name string) (snapshots.Snapshotter, error) {
675+
if name == "" {
676+
if err := c.GetLabel(ctx, defaults.DefaultSnapshotterNSLabel, &name, DefaultSnapshotter); err != nil {
677+
return nil, err
678+
}
679+
}
680+
676681
s := c.SnapshotService(name)
677682
if s == nil {
678683
return nil, errors.Wrapf(errdefs.ErrNotFound, "snapshotter %s was not found", name)

cmd/ctr/commands/commands.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"runtime"
2525
"strings"
2626

27-
"github.com/containerd/containerd"
2827
"github.com/urfave/cli"
2928
)
3029

@@ -34,7 +33,6 @@ var (
3433
cli.StringFlag{
3534
Name: "snapshotter",
3635
Usage: "snapshotter name. Empty value stands for the default value.",
37-
Value: containerd.DefaultSnapshotter,
3836
EnvVar: "CONTAINERD_SNAPSHOTTER",
3937
},
4038
}

container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (c *container) NewTask(ctx context.Context, ioCreate cio.Creator, opts ...N
233233
}
234234

235235
// get the rootfs from the snapshotter and add it to the request
236-
s, err := c.client.getSnapshotter(r.Snapshotter)
236+
s, err := c.client.getSnapshotter(ctx, r.Snapshotter)
237237
if err != nil {
238238
return nil, err
239239
}

container_opts.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
119117
func 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.

container_opts_unix.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool
5050
return err
5151
}
5252

53-
setSnapshotterIfEmpty(ctx, client, c)
54-
5553
var (
5654
parent = identity.ChainID(diffIDs).String()
5755
usernsID = fmt.Sprintf("%s-%d-%d", parent, uid, gid)
5856
)
59-
snapshotter, err := client.getSnapshotter(c.Snapshotter)
57+
snapshotter, err := client.getSnapshotter(ctx, c.Snapshotter)
6058
if err != nil {
6159
return err
6260
}

image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (i *image) Config(ctx context.Context) (ocispec.Descriptor, error) {
108108
}
109109

110110
func (i *image) IsUnpacked(ctx context.Context, snapshotterName string) (bool, error) {
111-
sn, err := i.client.getSnapshotter(snapshotterName)
111+
sn, err := i.client.getSnapshotter(ctx, snapshotterName)
112112
if err != nil {
113113
return false, err
114114
}
@@ -149,7 +149,7 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
149149
chain []digest.Digest
150150
unpacked bool
151151
)
152-
sn, err := i.client.getSnapshotter(snapshotterName)
152+
sn, err := i.client.getSnapshotter(ctx, snapshotterName)
153153
if err != nil {
154154
return err
155155
}

0 commit comments

Comments
 (0)