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

Bug 1890677: oc image: Include error msg when image not found and register oci schema for mediatypes #697

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cli/image/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (o *ExtractOptions) Run() error {
return imagemanifest.NewImageForbidden(msg, err)
}
if imagemanifest.IsImageNotFound(err) {
msg := fmt.Sprintf("image %q does not exist", from)
msg := fmt.Sprintf("image %q not found: %s", from, err.Error())
return imagemanifest.NewImageNotFound(msg, err)
}
return fmt.Errorf("unable to read image %s: %v", from, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/image/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (o *ImageRetriever) Run() error {
return callbackFn(name, nil, imagemanifest.NewImageForbidden(msg, err))
}
if imagemanifest.IsImageNotFound(err) {
msg := fmt.Sprintf("image %q does not exist", from)
msg := fmt.Sprintf("image %q not found: %s", from, err.Error())
return callbackFn(name, nil, imagemanifest.NewImageNotFound(msg, err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth updating NewImageNotFound to suffix non-nil errors? It just serializes as the msg today, but updating it would mean we'd get the err-level detail in all of our call-sites, not just this one. Although it's only one other call-site which has a chance at a non-nil error:

$ git --no-pager grep '\.NewImageNotFound('
pkg/cli/image/extract/extract.go:                                               return imagemanifest.NewImageNotFound(msg, err)
pkg/cli/image/info/info.go:                                             return callbackFn(name, nil, imagemanifest.NewImageNotFound(msg, err))
pkg/cli/image/info/info.go:                                     return imagemanifest.NewImageNotFound(fmt.Sprintf("no manifests could be found for %q", from), nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup I did notice there are others, I'll update

}
return callbackFn(name, nil, fmt.Errorf("unable to read image %s: %v", from, err))
Expand Down
26 changes: 26 additions & 0 deletions pkg/cli/image/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/docker/distribution"
"github.com/docker/distribution/manifest/manifestlist"
"github.com/docker/distribution/manifest/ocischema"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
"github.com/docker/distribution/reference"
Expand All @@ -24,6 +25,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/klog/v2"

imagespecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/openshift/library-go/pkg/image/dockerv1client"
imagereference "github.com/openshift/library-go/pkg/image/reference"
"github.com/openshift/library-go/pkg/image/registryclient"
Expand Down Expand Up @@ -211,6 +213,7 @@ type FilterFunc func(*manifestlist.ManifestDescriptor, bool) bool
var PreferManifestList = distribution.WithManifestMediaTypes([]string{
manifestlist.MediaTypeManifestList,
schema2.MediaTypeManifest,
imagespecv1.MediaTypeImageManifest,
})

// AllManifests returns all non-list manifests, the list manifest (if any), the digest the from refers to, or an error.
Expand Down Expand Up @@ -319,6 +322,29 @@ func ManifestToImageConfig(ctx context.Context, srcManifest distribution.Manifes

return base, layers, nil

case *ocischema.DeserializedManifest:
if t.Config.MediaType != imagespecv1.MediaTypeImageConfig {
return nil, nil, fmt.Errorf("%s does not have the expected image configuration media type: %s", location, t.Config.MediaType)
}
configJSON, err := blobs.Get(ctx, t.Config.Digest)
if err != nil {
return nil, nil, fmt.Errorf("cannot retrieve image configuration for %s: %v", location, err)
}
klog.V(4).Infof("Raw image config json:\n%s", string(configJSON))
config := &dockerv1client.DockerImageConfig{}
if err := json.Unmarshal(configJSON, &config); err != nil {
return nil, nil, fmt.Errorf("unable to parse image configuration: %v", err)
}

base := config
layers := t.Layers
base.Size = 0
for _, layer := range t.Layers {
base.Size += layer.Size
}

return base, layers, nil

case *schema1.SignedManifest:
if klog.V(4).Enabled() {
_, configJSON, _ := srcManifest.Payload()
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/image/mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/docker/distribution"
"github.com/docker/distribution/manifest/manifestlist"
"github.com/docker/distribution/manifest/ocischema"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
"github.com/docker/distribution/reference"
Expand Down Expand Up @@ -595,6 +596,7 @@ func (o *MirrorImageOptions) plan() (*plan, error) {
switch srcManifest.(type) {
case *schema2.DeserializedManifest:
case *schema1.SignedManifest:
case *ocischema.DeserializedManifest:
case *manifestlist.DeserializedManifestList:
// we do not need to upload layers in a manifestlist
continue
Expand Down
107 changes: 107 additions & 0 deletions vendor/github.com/docker/distribution/manifest/ocischema/builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions vendor/github.com/docker/distribution/manifest/ocischema/manifest.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ github.com/docker/distribution
github.com/docker/distribution/digestset
github.com/docker/distribution/manifest
github.com/docker/distribution/manifest/manifestlist
github.com/docker/distribution/manifest/ocischema
github.com/docker/distribution/manifest/schema1
github.com/docker/distribution/manifest/schema2
github.com/docker/distribution/metrics
Expand Down