From aec82c4cdf89dd17fe5c122257af1889718a9829 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Mon, 27 Nov 2017 12:37:03 +0000 Subject: [PATCH 1/2] Split config-related fields of Image into a substruct. Where "config-related" here means "ones you might find in the "org.mobyproject.config" label on an image. By making this new struct an anonymous member of the existing Image struct the Go json parser does the right thing (i.e. inlines into the parent) when parsing a complete image (from a yml assembly) by default. The Go yaml library which we use requires a tag on the anonymous field to achieve the same. Signed-off-by: Ian Campbell --- src/moby/config.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/moby/config.go b/src/moby/config.go index 9d4119cc4..d4f57c8aa 100644 --- a/src/moby/config.go +++ b/src/moby/config.go @@ -62,8 +62,14 @@ type File struct { // Image is the type of an image config type Image struct { - Name string `yaml:"name" json:"name"` - Image string `yaml:"image" json:"image"` + Name string `yaml:"name" json:"name"` + Image string `yaml:"image" json:"image"` + ImageConfig `yaml:",inline"` +} + +// ImageConfig is the configuration part of Image, it is the subset +// which is valid in a "org.mobyproject.config" label on an image. +type ImageConfig struct { Capabilities *[]string `yaml:"capabilities" json:"capabilities,omitempty"` Ambient *[]string `yaml:"ambient" json:"ambient,omitempty"` Mounts *[]specs.Mount `yaml:"mounts" json:"mounts,omitempty"` From f9893d9a9bb1f512c78dcf73612dde8372b5881f Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Mon, 27 Nov 2017 14:47:21 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Fixup=20test=20after=20Image=20=E2=86=92=20?= =?UTF-8?q?ImageConfig=20split.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The syntax used for the yaml definitions is changed by the need to include the substruct in the struct literal. For the label switch to `ImageConfig` directly, which is actually more correct in that it avoids spurious `name` and `image` fields in the label. Signed-off-by: Ian Campbell --- src/moby/config_test.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/moby/config_test.go b/src/moby/config_test.go index ebecb1fab..12f317b74 100644 --- a/src/moby/config_test.go +++ b/src/moby/config_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/docker/api/types/container" ) -func setupInspect(t *testing.T, label Image) types.ImageInspect { +func setupInspect(t *testing.T, label ImageConfig) types.ImageInspect { var inspect types.ImageInspect var config container.Config @@ -30,14 +30,16 @@ func TestOverrides(t *testing.T) { var yamlCaps = []string{"CAP_SYS_ADMIN"} var yaml = Image{ - Name: "test", - Image: "testimage", - Capabilities: &yamlCaps, + Name: "test", + Image: "testimage", + ImageConfig: ImageConfig{ + Capabilities: &yamlCaps, + }, } var labelCaps = []string{"CAP_SYS_CHROOT"} - var label = Image{ + var label = ImageConfig{ Capabilities: &labelCaps, Cwd: "/label/directory", } @@ -66,7 +68,7 @@ func TestInvalidCap(t *testing.T) { } labelCaps := []string{"NOT_A_CAP"} - var label = Image{ + var label = ImageConfig{ Capabilities: &labelCaps, } @@ -87,11 +89,13 @@ func TestIdMap(t *testing.T) { yaml := Image{ Name: "test", Image: "testimage", - UID: &uid, - GID: &gid, + ImageConfig: ImageConfig{ + UID: &uid, + GID: &gid, + }, } - var label = Image{} + var label = ImageConfig{} inspect := setupInspect(t, label)