Skip to content

Commit

Permalink
Allow config files to be mounted
Browse files Browse the repository at this point in the history
Because we wanted to reuse the layer uploading code, we wrap the config
bytes up as a Layer. Unfortunately, the partial.ConfigLayer
implementation doesn't preserve the fact that for mountable images, we
can perform a cross-repo mount.

This change updates partial.ConfigLayer to look for a ConfigLayer
implementation on the given image to see if it can simply dispatch to
that, falling back to calculating it from the config bytes otherwise.
  • Loading branch information
jonjohnsonjr committed Jun 15, 2022
1 parent 12aeccc commit 3e469c1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/v1/partial/compressed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ func TestRemote(t *testing.T) {
if got, want := ok, true; got != want {
t.Errorf("Exists() = %t != %t", got, want)
}

cl, err := partial.ConfigLayer(img)
if err != nil {
t.Fatal(err)
}
if _, ok := cl.(*remote.MountableLayer); !ok {
t.Errorf("ConfigLayer() expected to be MountableLayer, got %T", cl)
}
}

type noDiffID struct {
Expand Down
13 changes: 13 additions & 0 deletions pkg/v1/partial/with.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,22 @@ func (cl *configLayer) MediaType() (types.MediaType, error) {

var _ v1.Layer = (*configLayer)(nil)

// withConfigLayer allows partial image implementations to provide a layer
// for their config file.
type withConfigLayer interface {
ConfigLayer() (v1.Layer, error)
}

// ConfigLayer implements v1.Layer from the raw config bytes.
// This is so that clients (e.g. remote) can access the config as a blob.
//
// Images that want to return a specific layer implementation can implement
// withConfigLayer.
func ConfigLayer(i WithRawConfigFile) (v1.Layer, error) {
if wcl, ok := unwrap(i).(withConfigLayer); ok {
return wcl.ConfigLayer()
}

h, err := ConfigName(i)
if err != nil {
return nil, err
Expand Down
13 changes: 13 additions & 0 deletions pkg/v1/remote/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,16 @@ func (mi *mountableImage) LayerByDiffID(d v1.Hash) (v1.Layer, error) {
func (mi *mountableImage) Descriptor() (*v1.Descriptor, error) {
return partial.Descriptor(mi.Image)
}

// ConfigLayer retains the original reference so that it can be mounted.
// See partial.ConfigLayer.
func (mi *mountableImage) ConfigLayer() (v1.Layer, error) {
l, err := partial.ConfigLayer(mi.Image)
if err != nil {
return nil, err
}
return &MountableLayer{
Layer: l,
Reference: mi.Reference,
}, nil
}

0 comments on commit 3e469c1

Please sign in to comment.