Skip to content

Commit

Permalink
adding missing variant attribute in our Platform definition (#273)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante authored May 14, 2024
1 parent 9f7b96c commit 4af8786
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion image.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ type WithEditableLayers interface {

type Identifier fmt.Stringer

// Platform represents the target arch/os/os_version for an image construction and querying.
// Platform represents the target arch/os/variant/os_version for an image construction and querying.
type Platform struct {
Architecture string
OS string
Variant string
OSVersion string
}

Expand Down
15 changes: 15 additions & 0 deletions layout/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
layout.WithDefaultPlatform(imgutil.Platform{
Architecture: "arm",
OS: "windows",
Variant: "v1",
OSVersion: "10.0.17763.316",
}),
)
Expand All @@ -108,6 +109,10 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)
h.AssertEq(t, os, "windows")

variant, err := img.Variant()
h.AssertNil(t, err)
h.AssertEq(t, variant, "v1")

osVersion, err := img.OSVersion()
h.AssertNil(t, err)
h.AssertEq(t, osVersion, "10.0.17763.316")
Expand All @@ -122,6 +127,8 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
layout.WithDefaultPlatform(imgutil.Platform{
Architecture: "arm",
OS: "linux",
Variant: "v6",
OSVersion: "21.01",
}),
)
h.AssertNil(t, err)
Expand All @@ -136,6 +143,14 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)
h.AssertEq(t, os, "linux")

variant, err := img.Variant()
h.AssertNil(t, err)
h.AssertEq(t, variant, "v6")

osVersion, err := img.OSVersion()
h.AssertNil(t, err)
h.AssertEq(t, osVersion, "21.01")

_, err = img.TopLayer()
h.AssertError(t, err, "has no layers")
})
Expand Down
4 changes: 3 additions & 1 deletion layout/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func imageFromIndex(index v1.ImageIndex, platform imgutil.Platform) (v1.Image, e
} else {
for _, m := range manifestList.Manifests {
if m.Platform.OS == platform.OS &&
m.Platform.Architecture == platform.Architecture {
m.Platform.Architecture == platform.Architecture &&
m.Platform.Variant == platform.Variant &&
m.Platform.OSVersion == platform.OSVersion {
manifest = m
break
}
Expand Down
1 change: 1 addition & 0 deletions new.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func emptyV1(withPlatform Platform, withMediaTypes MediaTypes) (v1.Image, error)
History: []v1.History{},
OS: withPlatform.OS,
OSVersion: withPlatform.OSVersion,
Variant: withPlatform.Variant,
RootFS: v1.RootFS{
Type: "layers",
DiffIDs: []v1.Hash{},
Expand Down
2 changes: 2 additions & 0 deletions remote/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func processImageOption(repoName string, keychain authn.Keychain, withPlatform i
platform := v1.Platform{
Architecture: withPlatform.Architecture,
OS: withPlatform.OS,
Variant: withPlatform.Variant,
OSVersion: withPlatform.OSVersion,
}
reg := getRegistrySetting(repoName, withRegistrySettings)
Expand Down Expand Up @@ -153,6 +154,7 @@ func emptyImage(platform imgutil.Platform) (v1.Image, error) {
Architecture: platform.Architecture,
History: []v1.History{},
OS: platform.OS,
Variant: platform.Variant,
OSVersion: platform.OSVersion,
RootFS: v1.RootFS{
Type: "layers",
Expand Down
15 changes: 15 additions & 0 deletions remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
remote.WithDefaultPlatform(imgutil.Platform{
Architecture: "arm",
OS: "windows",
Variant: "v1",
OSVersion: "10.0.17763.316",
}),
)
Expand All @@ -137,6 +138,10 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)
h.AssertEq(t, os, "windows")

variant, err := img.Variant()
h.AssertNil(t, err)
h.AssertEq(t, variant, "v1")

osVersion, err := img.OSVersion()
h.AssertNil(t, err)
h.AssertEq(t, osVersion, "10.0.17763.316")
Expand All @@ -155,6 +160,8 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
remote.WithDefaultPlatform(imgutil.Platform{
Architecture: "arm",
OS: "linux",
Variant: "v6",
OSVersion: "21.01",
}),
)
h.AssertNil(t, err)
Expand All @@ -168,6 +175,14 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)
h.AssertEq(t, osName, "linux")

variant, err := img.Variant()
h.AssertNil(t, err)
h.AssertEq(t, variant, "v6")

osVersion, err := img.OSVersion()
h.AssertNil(t, err)
h.AssertEq(t, osVersion, "21.01")

_, err = img.TopLayer()
h.AssertError(t, err, "has no layers")
})
Expand Down

0 comments on commit 4af8786

Please sign in to comment.