Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add a paramter labels to CreateSnapshot #2569

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ctrd/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions ctrd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we should get somewhere to pass the label, or it will always be nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a snapshot-opt which keep options for snapshotter

return nil, err
}
cleanups = append(cleanups, func() error {
Expand Down
2 changes: 1 addition & 1 deletion daemon/mgr/container_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down