Skip to content

Commit 3fded74

Browse files
committed
Add unpack opts
Signed-off-by: Michael Crosby <[email protected]>
1 parent 26b9061 commit 3fded74

6 files changed

Lines changed: 32 additions & 11 deletions

File tree

diff.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ type diffRemote struct {
4848
func (r *diffRemote) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (ocispec.Descriptor, error) {
4949
var config diff.ApplyConfig
5050
for _, opt := range opts {
51-
if err := opt(&config); err != nil {
51+
if err := opt(ctx, desc, &config); err != nil {
5252
return ocispec.Descriptor{}, err
5353
}
5454
}
5555
req := &diffapi.ApplyRequest{
56-
Diff: fromDescriptor(desc),
57-
Mounts: fromMounts(mounts),
56+
Diff: fromDescriptor(desc),
57+
Mounts: fromMounts(mounts),
58+
Payloads: config.ProcessorPayloads,
5859
}
5960
resp, err := r.client.Apply(ctx, req)
6061
if err != nil {

diff/apply/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts [
6565

6666
var config diff.ApplyConfig
6767
for _, o := range opts {
68-
if err := o(&config); err != nil {
68+
if err := o(ctx, desc, &config); err != nil {
6969
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
7070
}
7171
}

diff/diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type ApplyConfig struct {
5959
}
6060

6161
// ApplyOpt is used to configure an Apply operation
62-
type ApplyOpt func(*ApplyConfig) error
62+
type ApplyOpt func(context.Context, ocispec.Descriptor, *ApplyConfig) error
6363

6464
// Applier allows applying diffs between mounts
6565
type Applier interface {
@@ -100,7 +100,7 @@ func WithLabels(labels map[string]string) Opt {
100100

101101
// WithPayloads sets the apply processor payloads to the config
102102
func WithPayloads(payloads map[string]*types.Any) ApplyOpt {
103-
return func(c *ApplyConfig) error {
103+
return func(_ context.Context, _ ocispec.Descriptor, c *ApplyConfig) error {
104104
c.ProcessorPayloads = payloads
105105
return nil
106106
}

diff/lcow/lcow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mou
108108

109109
var config diff.ApplyConfig
110110
for _, o := range opts {
111-
if err := o(&config); err != nil {
111+
if err := o(ctx, desc, &config); err != nil {
112112
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
113113
}
114114
}

diff/windows/windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
100100

101101
var config diff.ApplyConfig
102102
for _, o := range opts {
103-
if err := o(&config); err != nil {
103+
if err := o(ctx, desc, &config); err != nil {
104104
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
105105
}
106106
}

image.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import (
2121
"fmt"
2222

2323
"github.com/containerd/containerd/content"
24+
"github.com/containerd/containerd/diff"
2425
"github.com/containerd/containerd/errdefs"
2526
"github.com/containerd/containerd/images"
2627
"github.com/containerd/containerd/platforms"
2728
"github.com/containerd/containerd/rootfs"
29+
"github.com/containerd/containerd/snapshots"
2830
"github.com/opencontainers/go-digest"
2931
"github.com/opencontainers/image-spec/identity"
3032
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -40,7 +42,7 @@ type Image interface {
4042
// Labels of the image
4143
Labels() map[string]string
4244
// Unpack unpacks the image's content into a snapshot
43-
Unpack(context.Context, string) error
45+
Unpack(context.Context, string, ...UnpackOpt) error
4446
// RootFS returns the unpacked diffids that make up images rootfs.
4547
RootFS(ctx context.Context) ([]digest.Digest, error)
4648
// Size returns the total size of the image's packed resources.
@@ -130,13 +132,31 @@ func (i *image) IsUnpacked(ctx context.Context, snapshotterName string) (bool, e
130132
return false, nil
131133
}
132134

133-
func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
135+
// UnpackConfig provides configuration for the unpack of an image
136+
type UnpackConfig struct {
137+
// ApplyOpts for applying a diff to a snapshotter
138+
ApplyOpts []diff.ApplyOpt
139+
// SnapshotOpts for configuring a snapshotter
140+
SnapshotOpts []snapshots.Opt
141+
}
142+
143+
// UnpackOpt provides configuration for unpack
144+
type UnpackOpt func(context.Context, *UnpackConfig) error
145+
146+
func (i *image) Unpack(ctx context.Context, snapshotterName string, opts ...UnpackOpt) error {
134147
ctx, done, err := i.client.WithLease(ctx)
135148
if err != nil {
136149
return err
137150
}
138151
defer done(ctx)
139152

153+
var config UnpackConfig
154+
for _, o := range opts {
155+
if err := o(ctx, &config); err != nil {
156+
return err
157+
}
158+
}
159+
140160
layers, err := i.getLayers(ctx, i.platform)
141161
if err != nil {
142162
return err
@@ -158,7 +178,7 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
158178
return err
159179
}
160180
for _, layer := range layers {
161-
unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a)
181+
unpacked, err = rootfs.ApplyLayerWithOpts(ctx, layer, chain, sn, a, config.SnapshotOpts, config.ApplyOpts)
162182
if err != nil {
163183
return err
164184
}

0 commit comments

Comments
 (0)