diff --git a/ctrd/interface.go b/ctrd/interface.go index c7c7294fa..564b8d394 100644 --- a/ctrd/interface.go +++ b/ctrd/interface.go @@ -94,7 +94,7 @@ type ImageAPIClient interface { // SnapshotAPIClient provides access to containerd snapshot features type SnapshotAPIClient interface { // CreateSnapshot creates a active snapshot with image's name and id. - CreateSnapshot(ctx context.Context, id, ref string) error + CreateSnapshot(ctx context.Context, id, ref string, labels map[string]string) error // GetSnapshot returns the snapshot's info by id. GetSnapshot(ctx context.Context, id string) (snapshots.Info, error) // RemoveSnapshot removes the snapshot by id. diff --git a/ctrd/snapshot.go b/ctrd/snapshot.go index 753f8f36d..033c39a06 100644 --- a/ctrd/snapshot.go +++ b/ctrd/snapshot.go @@ -30,7 +30,7 @@ func CurrentSnapshotterName() string { } // CreateSnapshot creates a active snapshot with image's name and id. -func (c *Client) CreateSnapshot(ctx context.Context, id, ref string) error { +func (c *Client) CreateSnapshot(ctx context.Context, id, ref string, labels map[string]string) error { wrapperCli, err := c.Get(ctx) if err != nil { return fmt.Errorf("failed to get a containerd grpc client: %v", err) @@ -47,8 +47,10 @@ func (c *Client) CreateSnapshot(ctx context.Context, id, ref string) error { return err } + opts := []snapshots.Opt{snapshots.WithLabels(labels)} + parent := identity.ChainID(diffIDs).String() - _, err = wrapperCli.client.SnapshotService(CurrentSnapshotterName()).Prepare(ctx, id, parent) + _, err = wrapperCli.client.SnapshotService(defaultSnapshotterName).Prepare(ctx, id, parent, opts...) return err } diff --git a/daemon/mgr/container.go b/daemon/mgr/container.go index 91f09c8b7..6f4877673 100644 --- a/daemon/mgr/container.go +++ b/daemon/mgr/container.go @@ -383,7 +383,7 @@ func (mgr *ContainerManager) Create(ctx context.Context, name string, config *ty snapID := id // create a snapshot with image. - if err := mgr.Client.CreateSnapshot(ctx, snapID, config.Image); err != nil { + if err := mgr.Client.CreateSnapshot(ctx, snapID, config.Image, nil); err != nil { return nil, err } cleanups = append(cleanups, func() error { diff --git a/daemon/mgr/container_upgrade.go b/daemon/mgr/container_upgrade.go index 0cb848beb..bffd5bec4 100644 --- a/daemon/mgr/container_upgrade.go +++ b/daemon/mgr/container_upgrade.go @@ -170,7 +170,7 @@ func (mgr *ContainerManager) prepareSnapshotForUpgrade(ctx context.Context, cID, } // create a snapshot with image for new container. - if err := mgr.Client.CreateSnapshot(ctx, newSnapID, image); err != nil { + if err := mgr.Client.CreateSnapshot(ctx, newSnapID, image, nil); err != nil { return "", errors.Wrap(err, "failed to create snapshot") }