From 7abcfb6d0ddacec526f92c87ab0e891518a33f84 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Thu, 6 Jan 2022 12:17:29 -0800 Subject: [PATCH] pkg/v1/mutate: fill in mediaType for OCI --- pkg/v1/mutate/image.go | 9 +-------- pkg/v1/mutate/index.go | 9 +-------- pkg/v1/mutate/mutate_test.go | 8 ++++---- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/pkg/v1/mutate/image.go b/pkg/v1/mutate/image.go index 834cee15f..93c230e3b 100644 --- a/pkg/v1/mutate/image.go +++ b/pkg/v1/mutate/image.go @@ -18,7 +18,6 @@ import ( "bytes" "encoding/json" "errors" - "strings" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/partial" @@ -141,14 +140,8 @@ func (i *image) compute() error { manifest.Config.MediaType = *i.configMediaType } - // With OCI media types, this should not be set, see discussion: - // https://github.com/opencontainers/image-spec/pull/795 if i.mediaType != nil { - if strings.Contains(string(*i.mediaType), types.OCIVendorPrefix) { - manifest.MediaType = "" - } else if strings.Contains(string(*i.mediaType), types.DockerVendorPrefix) { - manifest.MediaType = *i.mediaType - } + manifest.MediaType = *i.mediaType } if i.annotations != nil { diff --git a/pkg/v1/mutate/index.go b/pkg/v1/mutate/index.go index d9694b29e..841995f15 100644 --- a/pkg/v1/mutate/index.go +++ b/pkg/v1/mutate/index.go @@ -17,7 +17,6 @@ package mutate import ( "encoding/json" "fmt" - "strings" "github.com/google/go-containerregistry/pkg/logs" v1 "github.com/google/go-containerregistry/pkg/v1" @@ -131,14 +130,8 @@ func (i *index) compute() error { manifest.Manifests = manifests - // With OCI media types, this should not be set, see discussion: - // https://github.com/opencontainers/image-spec/pull/795 if i.mediaType != nil { - if strings.Contains(string(*i.mediaType), types.OCIVendorPrefix) { - manifest.MediaType = "" - } else if strings.Contains(string(*i.mediaType), types.DockerVendorPrefix) { - manifest.MediaType = *i.mediaType - } + manifest.MediaType = *i.mediaType } if i.annotations != nil { diff --git a/pkg/v1/mutate/mutate_test.go b/pkg/v1/mutate/mutate_test.go index 40dfb2f03..c9433575d 100644 --- a/pkg/v1/mutate/mutate_test.go +++ b/pkg/v1/mutate/mutate_test.go @@ -358,8 +358,8 @@ func TestMutateMediaType(t *testing.T) { if err != nil { t.Fatal(err) } - if manifest.MediaType != "" { - t.Errorf("MediaType should not be set for OCI media types: %v", manifest.MediaType) + if manifest.MediaType == "" { + t.Error("MediaType should be set for OCI media types") } if gotCfg := manifest.Config.MediaType; gotCfg != wantCfg { t.Errorf("manifest.Config.MediaType = %v, wanted %v", gotCfg, wantCfg) @@ -400,8 +400,8 @@ func TestMutateMediaType(t *testing.T) { if err != nil { t.Fatal(err) } - if im.MediaType != "" { - t.Errorf("MediaType should not be set for OCI media types: %v", im.MediaType) + if im.MediaType == "" { + t.Error("MediaType should be set for OCI media types") } want = types.DockerManifestList