From 3e508b4b08b89cea0ab357b849db835d4ea03c53 Mon Sep 17 00:00:00 2001 From: Matthew Endsley Date: Fri, 1 Nov 2024 01:11:46 -0700 Subject: [PATCH] Forward all labels to the snapshotter Ideally we would have separate snapshotter labels such as with the `--snapshotter-label` option to `ctr container create`. The containerd daemon will automatically filter out labels that don't match a snapshotter and I really don't want to add a new field to the server API right now. /shurg --- daemon/containerd/image_snapshot.go | 7 +++++-- daemon/create.go | 2 +- daemon/image_service.go | 2 +- daemon/images/image.go | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/daemon/containerd/image_snapshot.go b/daemon/containerd/image_snapshot.go index 004a0fbdf37dd..cb6af32789853 100644 --- a/daemon/containerd/image_snapshot.go +++ b/daemon/containerd/image_snapshot.go @@ -18,7 +18,7 @@ import ( ) // PrepareSnapshot prepares a snapshot from a parent image for a container -func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform, setupInit func(string) error) error { +func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform, setupInit func(string) error, labels map[string]string) error { var parentSnapshot string if parentImage != "" { img, err := i.resolveImage(ctx, parentImage) @@ -72,7 +72,10 @@ func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentIma return i.remapSnapshot(ctx, snapshotter, id, id+"-init") } - _, err = snapshotter.Prepare(ctx, id, id+"-init") + sops := []snapshots.Opt { + snapshots.WithLabels(labels), + } + _, err = snapshotter.Prepare(ctx, id, id+"-init", sops...) return err } diff --git a/daemon/create.go b/daemon/create.go index 3e2227f74379f..fe1be51fb6783 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -197,7 +197,7 @@ func (daemon *Daemon) create(ctx context.Context, daemonCfg *config.Config, opts ctr.ImageManifest = imgManifest if daemon.UsesSnapshotter() { - if err := daemon.imageService.PrepareSnapshot(ctx, ctr.ID, opts.params.Config.Image, opts.params.Platform, setupInitLayer(daemon.idMapping)); err != nil { + if err := daemon.imageService.PrepareSnapshot(ctx, ctr.ID, opts.params.Config.Image, opts.params.Platform, setupInitLayer(daemon.idMapping), opts.params.Config.Labels); err != nil { return nil, err } } else { diff --git a/daemon/image_service.go b/daemon/image_service.go index 94606b3aaf7f5..fe969d88746cf 100644 --- a/daemon/image_service.go +++ b/daemon/image_service.go @@ -47,7 +47,7 @@ type ImageService interface { // Containerd related methods - PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform, setupInit func(string) error) error + PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform, setupInit func(string) error, labels map[string]string) error GetImageManifest(ctx context.Context, refOrID string, options backend.GetImageOpts) (*ocispec.Descriptor, error) // Layers diff --git a/daemon/images/image.go b/daemon/images/image.go index d94d14237ecdf..7f04d85543e87 100644 --- a/daemon/images/image.go +++ b/daemon/images/image.go @@ -45,7 +45,7 @@ type manifest struct { Config ocispec.Descriptor `json:"config"` } -func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform, setupInit func(string) error) error { +func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform, setupInit func(string) error, labels map[string]string) error { // Only makes sense when containerd image store is used panic("not implemented") }