Skip to content

Commit caa5f49

Browse files
committed
Forward all labels to the snapshotter
This is primarily motivated by the desire to create windows containers with a rootfs size larger than the snapshotter default. This can be acheived with the `ctr run` command with the `--snapshotter-label` argument. The snapshotter filters labels for which it has an interest and ignores others, so this change simply forwards all supplied labels instead of making an API change. For the two cases below the commands run are: 1. `docker run --rm -it mcr.microsoft.com/windows/servercore:ltsc2022 powershell -Command "(gdr C).Free + (gdr C).Used"` 2. `docker run --label "containerd.io/snapshot/windows/rootfs.sizebytes=32212254720" --rm -it mcr.microsoft.com/windows/servercore:ltsc2022 powershell -Command "(gdr C).Free + (gdr C).Used"` Before this change: ------------------- Output from 1: `21339549696` Output from 2: `21339549696` After this change: ------------------ Output from 1: `21339549696` Output from 2: `32076963840`
1 parent b0e8932 commit caa5f49

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

daemon/containerd/image_snapshot.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
// CreateLayer creates a new layer for a container.
24-
func (i *ImageService) CreateLayer(ctr *container.Container, initFunc layer.MountInit) (container.RWLayer, error) {
24+
func (i *ImageService) CreateLayer(ctr *container.Container, initFunc layer.MountInit, labels map[string]string) (container.RWLayer, error) {
2525
var descriptor *ocispec.Descriptor
2626
if ctr.ImageManifest != nil {
2727
descriptor = ctr.ImageManifest
@@ -31,7 +31,7 @@ func (i *ImageService) CreateLayer(ctr *container.Container, initFunc layer.Moun
3131
StorageOpt: ctr.HostConfig.StorageOpt,
3232
}
3333

34-
return i.createLayer(descriptor, ctr.ID, rwLayerOpts, initFunc)
34+
return i.createLayer(descriptor, ctr.ID, rwLayerOpts, initFunc, labels)
3535
}
3636

3737
// CreateLayerFromImage creates a new layer from an image
@@ -41,10 +41,10 @@ func (i *ImageService) CreateLayerFromImage(img *image.Image, layerName string,
4141
descriptor = img.Details.ManifestDescriptor
4242
}
4343

44-
return i.createLayer(descriptor, layerName, rwLayerOpts, nil)
44+
return i.createLayer(descriptor, layerName, rwLayerOpts, nil, nil)
4545
}
4646

47-
func (i *ImageService) createLayer(descriptor *ocispec.Descriptor, layerName string, rwLayerOpts *layer.CreateRWLayerOpts, initFunc layer.MountInit) (container.RWLayer, error) {
47+
func (i *ImageService) createLayer(descriptor *ocispec.Descriptor, layerName string, rwLayerOpts *layer.CreateRWLayerOpts, initFunc layer.MountInit, labels map[string]string) (container.RWLayer, error) {
4848
ctx := context.TODO()
4949
var parentSnapshot string
5050
if descriptor != nil {
@@ -78,7 +78,11 @@ func (i *ImageService) createLayer(descriptor *ocispec.Descriptor, layerName str
7878
if !i.idMapping.Empty() {
7979
err = i.remapSnapshot(ctx, sn, layerName, parentSnapshot)
8080
} else {
81-
_, err = sn.Prepare(ctx, layerName, parentSnapshot)
81+
sopts := []snapshots.Opt {
82+
snapshots.WithLabels(labels),
83+
}
84+
85+
_, err = sn.Prepare(ctx, layerName, parentSnapshot, sopts...)
8286
}
8387

8488
if err != nil {

daemon/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (daemon *Daemon) create(ctx context.Context, daemonCfg *config.Config, opts
228228
ctr.ImageManifest = imgManifest
229229

230230
// Set RWLayer for container after mount labels have been set
231-
rwLayer, err := daemon.imageService.CreateLayer(ctr, setupInitLayer(daemon.idMapping.RootPair()))
231+
rwLayer, err := daemon.imageService.CreateLayer(ctr, setupInitLayer(daemon.idMapping.RootPair()), opts.params.Config.Labels)
232232
if err != nil {
233233
return nil, errdefs.System(err)
234234
}

daemon/image_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type ImageService interface {
4747
// Layers
4848

4949
GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error)
50-
CreateLayer(container *container.Container, initFunc layer.MountInit) (container.RWLayer, error)
50+
CreateLayer(container *container.Container, initFunc layer.MountInit, labels map[string]string) (container.RWLayer, error)
5151
CreateLayerFromImage(img *image.Image, layerName string, rwLayerOpts *layer.CreateRWLayerOpts) (container.RWLayer, error)
5252
GetLayerByID(cid string) (container.RWLayer, error)
5353
LayerStoreStatus() [][2]string

daemon/images/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (i *ImageService) Children(_ context.Context, id image.ID) ([]image.ID, err
118118
// CreateLayer creates a filesystem layer for a container.
119119
// called from create.go
120120
// TODO: accept an opt struct instead of container?
121-
func (i *ImageService) CreateLayer(container *container.Container, initFunc layer.MountInit) (container.RWLayer, error) {
121+
func (i *ImageService) CreateLayer(container *container.Container, initFunc layer.MountInit, labels map[string]string) (container.RWLayer, error) {
122122
var img *image.Image
123123
if container.ImageID != "" {
124124
containerImg, err := i.imageStore.Get(container.ImageID)

0 commit comments

Comments
 (0)