Skip to content

Commit

Permalink
revert remote
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Feb 22, 2024
1 parent 998d98b commit b69ebe4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 44 deletions.
35 changes: 3 additions & 32 deletions pkg/v1/remote/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package remote
import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -63,40 +62,12 @@ var _ partial.CompressedImageCore = (*remoteImage)(nil)

// Image provides access to a remote image reference.
func Image(ref name.Reference, options ...Option) (v1.Image, error) {
opts, err := makeOptions(options...)
desc, err := Get(ref, options...)
if err != nil {
return nil, err
}
desc, err := Artifact(ref, options...)
if err != nil {
return nil, err
}
if img, ok := desc.(v1.Image); ok {
return img, nil
}
if idx, ok := desc.(v1.ImageIndex); ok && opts.platform.String() != "" {
index, err := idx.IndexManifest()
if err != nil {
return nil, err
}
for _, childDesc := range index.Manifests {
// If platform is missing from child descriptor, assume it's amd64/linux.
p := defaultPlatform
if childDesc.Platform != nil {
p = *childDesc.Platform
}

if matchesPlatform(p, opts.platform) {
return idx.Image(childDesc.Digest)
}
}
return nil, fmt.Errorf("no child with platform %+v in index %s", opts.platform, ref)
}
mt, err := desc.MediaType()
if err != nil {
return nil, err
}
return nil, fmt.Errorf("%s is not an image, media type is %s", ref, mt)

return desc.Image()
}

func (r *remoteImage) MediaType() (types.MediaType, error) {
Expand Down
3 changes: 0 additions & 3 deletions pkg/v1/remote/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ func TestImage(t *testing.T) {
if r.Method != http.MethodGet {
t.Errorf("Method; got %v, want %v", r.Method, http.MethodGet)
}
w.Header().Add("Content-type", string(mustMediaType(t, img)))
w.Write(mustRawManifest(t, img))
case layerPath:
t.Fatalf("BlobSize should not make any request: %v", r.URL.Path)
Expand Down Expand Up @@ -431,7 +430,6 @@ func TestPullingManifestList(t *testing.T) {
if r.Method != http.MethodGet {
t.Errorf("Method; got %v, want %v", r.Method, http.MethodGet)
}
w.Header().Set("Content-Type", string(mustMediaType(t, child)))
w.Write(mustRawManifest(t, child))
case configPath:
if r.Method != http.MethodGet {
Expand Down Expand Up @@ -634,7 +632,6 @@ func TestPullingForeignLayer(t *testing.T) {
if r.Method != http.MethodGet {
t.Errorf("Method; got %v, want %v", r.Method, http.MethodGet)
}
w.Header().Add("Content-Type", string(mustMediaType(t, img)))
w.Write(mustRawManifest(t, img))
case layerPath:
compressed, err := layer.Compressed()
Expand Down
12 changes: 3 additions & 9 deletions pkg/v1/remote/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,12 @@ type remoteIndex struct {

// Index provides access to a remote index reference.
func Index(ref name.Reference, options ...Option) (v1.ImageIndex, error) {
desc, err := artifact(ref, acceptableIndexMediaTypes, options...)
desc, err := get(ref, acceptableIndexMediaTypes, options...)
if err != nil {
return nil, err
}
if idx, ok := desc.(v1.ImageIndex); ok {
return idx, nil
}
mt, err := desc.MediaType()
if err != nil {
return nil, err
}
return nil, fmt.Errorf("%s is not an image index, media type is %s", ref, mt)

return desc.ImageIndex()
}

func (r *remoteIndex) MediaType() (types.MediaType, error) {
Expand Down

0 comments on commit b69ebe4

Please sign in to comment.