Skip to content

Commit 9b70de0

Browse files
authored
Merge pull request #4630 from dcantah/pass-snapshotter-opt
Cri - Pass snapshotter labels into customopts.WithNewSnapshot
2 parents be47c2d + 9a1f6ea commit 9b70de0

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

pkg/cri/opts/container.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ import (
2727
"github.com/containerd/containerd/errdefs"
2828
"github.com/containerd/containerd/log"
2929
"github.com/containerd/containerd/mount"
30+
"github.com/containerd/containerd/snapshots"
3031
"github.com/containerd/continuity/fs"
3132
"github.com/pkg/errors"
3233
)
3334

3435
// WithNewSnapshot wraps `containerd.WithNewSnapshot` so that if creating the
3536
// snapshot fails we make sure the image is actually unpacked and and retry.
36-
func WithNewSnapshot(id string, i containerd.Image) containerd.NewContainerOpts {
37-
f := containerd.WithNewSnapshot(id, i)
37+
func WithNewSnapshot(id string, i containerd.Image, opts ...snapshots.Opt) containerd.NewContainerOpts {
38+
f := containerd.WithNewSnapshot(id, i, opts...)
3839
return func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
3940
if err := f(ctx, client, c); err != nil {
4041
if !errdefs.IsNotFound(err) {

pkg/cri/server/container_create.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/containerd/containerd/containers"
2525
"github.com/containerd/containerd/log"
2626
"github.com/containerd/containerd/oci"
27+
"github.com/containerd/containerd/snapshots"
2728
"github.com/containerd/typeurl"
2829
"github.com/davecgh/go-spew/spew"
2930
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -180,6 +181,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
180181

181182
log.G(ctx).Debugf("Container %q spec: %#+v", id, spew.NewFormatter(spec))
182183

184+
snapshotterOpt := snapshots.WithLabels(config.Annotations)
183185
// Set snapshotter before any other options.
184186
opts := []containerd.NewContainerOpts{
185187
containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter),
@@ -188,7 +190,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
188190
// the runtime (runc) a chance to modify (e.g. to create mount
189191
// points corresponding to spec.Mounts) before making the
190192
// rootfs readonly (requested by spec.Root.Readonly).
191-
customopts.WithNewSnapshot(id, containerdImage),
193+
customopts.WithNewSnapshot(id, containerdImage, snapshotterOpt),
192194
}
193195
if len(volumeMounts) > 0 {
194196
mountMap := make(map[string]string)

pkg/cri/server/sandbox_run.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/containerd/containerd/pkg/cri/util"
4545
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
4646
"github.com/containerd/containerd/pkg/netns"
47+
"github.com/containerd/containerd/snapshots"
4748
selinux "github.com/opencontainers/selinux/go-selinux"
4849
)
4950

@@ -190,9 +191,11 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
190191
if err != nil {
191192
return nil, errors.Wrap(err, "failed to generate runtime options")
192193
}
194+
195+
snapshotterOpt := snapshots.WithLabels(config.Annotations)
193196
opts := []containerd.NewContainerOpts{
194197
containerd.WithSnapshotter(c.config.ContainerdConfig.Snapshotter),
195-
customopts.WithNewSnapshot(id, containerdImage),
198+
customopts.WithNewSnapshot(id, containerdImage, snapshotterOpt),
196199
containerd.WithSpec(spec, specOpts...),
197200
containerd.WithContainerLabels(sandboxLabels),
198201
containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata),

snapshots/lcow/lcow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
346346
defer scratchSource.Close()
347347

348348
// TODO: JTERRY75 - This has to be called sandbox.vhdx for the time
349-
// being but it really is the scratch.vhdx Using this naming convention
349+
// being but it really is the scratch.vhdx. Using this naming convention
350350
// for now but this is not the kubernetes sandbox.
351351
//
352352
// Create the sandbox.vhdx for this snapshot from the cache.
@@ -371,7 +371,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
371371
}
372372

373373
func (s *snapshotter) openOrCreateScratch(ctx context.Context, sizeGB int) (_ *os.File, err error) {
374-
// Create the scratch.vhdx cache file if it doesn't already exit.
374+
// Create the scratch.vhdx cache file if it doesn't already exist.
375375
s.scratchLock.Lock()
376376
defer s.scratchLock.Unlock()
377377

0 commit comments

Comments
 (0)