Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/v1/mutate: fill in mediaType for OCI #1236

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions pkg/v1/mutate/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 1 addition & 8 deletions pkg/v1/mutate/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/v1/mutate/mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down