Skip to content

Commit baf3403

Browse files
committed
Extend Applier's Apply() method with an optional options parameter
Extend the Applier interface's Apply method with an optional options parameter. For the container image encryption we intend to use the options parameter to pass image decryption parameters ('dcparameters'), which are primarily (privatte) keys, in form of a JSON document under the map key '_dcparameters', and pass them to the Applier's Apply() method. This helps us to access decryption keys and start the pipeline with the layer decryption before the layer data are unzipped and untarred. Signed-off-by: Stefan Berger <[email protected]> Signed-off-by: Harshal Patil <[email protected]>
1 parent 9b882c4 commit baf3403

6 files changed

Lines changed: 22 additions & 7 deletions

File tree

diff.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ type diffRemote struct {
4545
client diffapi.DiffClient
4646
}
4747

48-
func (r *diffRemote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []mount.Mount) (ocispec.Descriptor, error) {
48+
func (r *diffRemote) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (ocispec.Descriptor, error) {
49+
var config diff.ApplyConfig
50+
for _, opt := range opts {
51+
if err := opt(&config); err != nil {
52+
return ocispec.Descriptor{}, err
53+
}
54+
}
4955
req := &diffapi.ApplyRequest{
50-
Diff: fromDescriptor(diff),
56+
Diff: fromDescriptor(desc),
5157
Mounts: fromMounts(mounts),
5258
}
5359
resp, err := r.client.Apply(ctx, req)

diff/apply/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var emptyDesc = ocispec.Descriptor{}
5353
// Apply applies the content associated with the provided digests onto the
5454
// provided mounts. Archive content will be extracted and decompressed if
5555
// necessary.
56-
func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) {
56+
func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) {
5757
t1 := time.Now()
5858
defer func() {
5959
if err == nil {

diff/diff.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,21 @@ type Comparer interface {
5151
Compare(ctx context.Context, lower, upper []mount.Mount, opts ...Opt) (ocispec.Descriptor, error)
5252
}
5353

54+
// ApplyConfig is used to hold parameters needed for a apply operation
55+
type ApplyConfig struct {
56+
}
57+
58+
// ApplyOpt is used to configure an Apply operation
59+
type ApplyOpt func(*ApplyConfig) error
60+
5461
// Applier allows applying diffs between mounts
5562
type Applier interface {
5663
// Apply applies the content referred to by the given descriptor to
5764
// the provided mount. The method of applying is based on the
5865
// implementation and content descriptor. For example, in the common
5966
// case the descriptor is a file system difference in tar format,
6067
// that tar would be applied on top of the mounts.
61-
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount) (ocispec.Descriptor, error)
68+
Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount, opts ...ApplyOpt) (ocispec.Descriptor, error)
6269
}
6370

6471
// WithMediaType sets the media type to use for creating the diff, without

diff/lcow/lcow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func NewWindowsLcowDiff(store content.Store) (CompareApplier, error) {
9595
// Apply applies the content associated with the provided digests onto the
9696
// provided mounts. Archive content will be extracted and decompressed if
9797
// necessary.
98-
func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) {
98+
func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) {
9999
t1 := time.Now()
100100
defer func() {
101101
if err == nil {

diff/windows/windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewWindowsDiff(store content.Store) (CompareApplier, error) {
8787
// Apply applies the content associated with the provided digests onto the
8888
// provided mounts. Archive content will be extracted and decompressed if
8989
// necessary.
90-
func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) {
90+
func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) {
9191
t1 := time.Now()
9292
defer func() {
9393
if err == nil {

services/diff/local.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ func (l *local) Apply(ctx context.Context, er *diffapi.ApplyRequest, _ ...grpc.C
9999
mounts = toMounts(er.Mounts)
100100
)
101101

102+
var opts []diff.ApplyOpt
103+
102104
for _, differ := range l.differs {
103-
ocidesc, err = differ.Apply(ctx, desc, mounts)
105+
ocidesc, err = differ.Apply(ctx, desc, mounts, opts...)
104106
if !errdefs.IsNotImplemented(err) {
105107
break
106108
}

0 commit comments

Comments
 (0)