diff --git a/client/client_export_metadata_test.go b/client/client_export_metadata_test.go index 1e77d7dc7325..4251103af4f2 100644 --- a/client/client_export_metadata_test.go +++ b/client/client_export_metadata_test.go @@ -426,13 +426,13 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) { "name": target, "push": "true", "annotation-index.gio": "generic index opt", - "annotation-index." + ocispecs.AnnotationCreated: created, - "annotation-manifest.gmo": "generic manifest opt", - "annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt", - "annotation-manifest[linux/amd64].mo": "amd64 manifest opt", - "annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt", - "annotation-manifest[linux/arm64].mo": "arm64 manifest opt", - "annotation-manifest-descriptor[linux/arm64].mdo": "arm64 manifest descriptor opt", + "annotation-index." + ocispecs.AnnotationCreated: created, + "annotation-manifest.gmo": "generic manifest opt", + "annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt", + "annotation-manifest[linux/amd64].mo": "amd64 manifest opt", + "annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt", + "annotation-manifest[linux/arm64/v8].mo": "arm64 manifest opt", + "annotation-manifest-descriptor[linux/arm64/v8].mdo": "arm64 manifest descriptor opt", }, }, }, @@ -498,8 +498,8 @@ func testExportAnnotations(t *testing.T, sb integration.Sandbox) { "annotation-manifest-descriptor.gmdo": "generic manifest descriptor opt", "annotation-manifest[linux/amd64].mo": "amd64 manifest opt", "annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt", - "annotation-manifest[linux/arm64].mo": "arm64 manifest opt", - "annotation-manifest-descriptor[linux/arm64].mdo": "arm64 manifest descriptor opt", + "annotation-manifest[linux/arm64/v8].mo": "arm64 manifest opt", + "annotation-manifest-descriptor[linux/arm64/v8].mdo": "arm64 manifest descriptor opt", }, }, }, diff --git a/exporter/containerimage/exptypes/annotations.go b/exporter/containerimage/exptypes/annotations.go index a9b74d6b9681..6b77014ccdef 100644 --- a/exporter/containerimage/exptypes/annotations.go +++ b/exporter/containerimage/exptypes/annotations.go @@ -103,6 +103,7 @@ func ParseAnnotationKey(result string) (AnnotationKey, bool, error) { if err != nil { return AnnotationKey{}, true, err } + p = platforms.Normalize(p) ociPlatform = &p } diff --git a/exporter/containerimage/exptypes/annotations_test.go b/exporter/containerimage/exptypes/annotations_test.go new file mode 100644 index 000000000000..0f2f260b61bd --- /dev/null +++ b/exporter/containerimage/exptypes/annotations_test.go @@ -0,0 +1,32 @@ +package exptypes + +import ( + "testing" + + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/stretchr/testify/require" +) + +func TestParseAnnotationKeyPlatform(t *testing.T) { + for _, tc := range []struct { + platform string + want ocispecs.Platform + }{ + {"linux/arm64", ocispecs.Platform{OS: "linux", Architecture: "arm64"}}, + {"linux/arm64/v8", ocispecs.Platform{OS: "linux", Architecture: "arm64"}}, + {"linux/arm64/8", ocispecs.Platform{OS: "linux", Architecture: "arm64"}}, + {"linux/arm64/v9", ocispecs.Platform{OS: "linux", Architecture: "arm64", Variant: "v9"}}, + {"linux/arm", ocispecs.Platform{OS: "linux", Architecture: "arm", Variant: "v7"}}, + {"linux/arm/v6", ocispecs.Platform{OS: "linux", Architecture: "arm", Variant: "v6"}}, + {"linux/arm/v7", ocispecs.Platform{OS: "linux", Architecture: "arm", Variant: "v7"}}, + } { + for _, typ := range []string{AnnotationManifest, AnnotationManifestDescriptor} { + t.Run(typ+"/"+tc.platform, func(t *testing.T) { + key, ok, err := ParseAnnotationKey("annotation-" + typ + "[" + tc.platform + "].example") + require.NoError(t, err) + require.True(t, ok) + require.Equal(t, AnnotationKey{Type: typ, Platform: &tc.want, Key: "example"}, key) + }) + } + } +}