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

Change name of v1.Status to v1.PullStatus to provide a more accurate name #433

Merged
merged 1 commit into from
Sep 2, 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
48 changes: 26 additions & 22 deletions pkg/imgpkg/v1/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,34 @@ func newBundleInfo(node bundle.GraphNode, updated bool) BundleInfo {
}

// Status Report from the Pull command
type Status struct {
// Deprecated: in favor of PullStatus, the name makes more sense for API.
type Status PullStatus

// PullStatus Report from the Pull command
type PullStatus struct {
BundleInfo
IsBundle bool `json:"-"`
Cacheable bool `json:"cacheable"`
}

// Pull Download the contents of the image referenced by imageRef to the folder outputPath
func Pull(imageRef string, outputPath string, pullOptions PullOpts, registryOpts registry.Opts) (Status, error) {
func Pull(imageRef string, outputPath string, pullOptions PullOpts, registryOpts registry.Opts) (PullStatus, error) {
reg, err := registry.NewSimpleRegistry(registryOpts)
if err != nil {
return Status{}, err
return PullStatus{}, err
}

bundleToPull := bundle.NewBundle(imageRef, reg)
isBundle, err := bundleToPull.IsBundle()
if err != nil {
return Status{}, err
return PullStatus{}, err
}

switch {
case isBundle && pullOptions.AsImage: // Trying to pull the OCI Image of a Bundle
st, err := pullImage(imageRef, outputPath, pullOptions, reg)
if err != nil {
return Status{}, err
return PullStatus{}, err
}
st.IsBundle = true
return st, nil
Expand All @@ -105,53 +109,53 @@ func Pull(imageRef string, outputPath string, pullOptions PullOpts, registryOpts
return pullBundle(imageRef, bundleToPull, outputPath, pullOptions, false)

case !isBundle && pullOptions.IsBundle: // Trying to pull an Image as a Bundle
return Status{}, &ErrIsNotBundle{}
return PullStatus{}, &ErrIsNotBundle{}

case !isBundle && !pullOptions.IsBundle: // Trying to pull an OCI Image
return pullImage(imageRef, outputPath, pullOptions, reg)

case isBundle && !pullOptions.IsBundle: // Trying to pull a Bundle as if it where an OCI Image
return Status{}, &ErrIsBundle{}
return PullStatus{}, &ErrIsBundle{}
}

return Status{}, fmt.Errorf("Unknown option")
return PullStatus{}, fmt.Errorf("Unknown option")
}

// PullRecursive Downloads the contents of the Bundle and Nested Bundles referenced by imageRef to the folder outputPath.
// This functions should error out when imageRef does not point to a Bundle
func PullRecursive(imageRef string, outputPath string, pullOptions PullOpts, registryOpts registry.Opts) (Status, error) {
func PullRecursive(imageRef string, outputPath string, pullOptions PullOpts, registryOpts registry.Opts) (PullStatus, error) {
reg, err := registry.NewSimpleRegistry(registryOpts)
if err != nil {
return Status{}, err
return PullStatus{}, err
}

bundleToPull := bundle.NewBundle(imageRef, reg)
isBundle, err := bundleToPull.IsBundle()
if err != nil {
return Status{}, err
return PullStatus{}, err
}
if !isBundle {
return Status{}, &ErrIsNotBundle{}
return PullStatus{}, &ErrIsNotBundle{}
}

return pullBundle(imageRef, bundleToPull, outputPath, pullOptions, true)
}

// pullBundle Downloads the contents of the Bundle Image referenced by imageRef to the folder outputPath.
// This functions should error out when imageRef does not point to a Bundle
func pullBundle(imgRef string, bundleToPull *bundle.Bundle, outputPath string, pullOptions PullOpts, pullNestedBundles bool) (Status, error) {
func pullBundle(imgRef string, bundleToPull *bundle.Bundle, outputPath string, pullOptions PullOpts, pullNestedBundles bool) (PullStatus, error) {
isRootBundleRelocated, err := bundleToPull.Pull(outputPath, pullOptions.Logger, pullNestedBundles)
if err != nil {
return Status{}, err
return PullStatus{}, err
}

isCacheable, err := isCacheable(imgRef, isRootBundleRelocated)
if err != nil {
return Status{}, err
return PullStatus{}, err
}

bInfo := buildBundleInfoFromBundle(bundleToPull, isRootBundleRelocated)
return Status{
return PullStatus{
BundleInfo: BundleInfo{
ImageRef: bundleToPull.DigestRef(),
ImagesLock: &ImagesLockInfo{
Expand All @@ -165,25 +169,25 @@ func pullBundle(imgRef string, bundleToPull *bundle.Bundle, outputPath string, p
}, nil
}

func pullImage(imageRef string, outputPath string, pullOptions PullOpts, reg registry.Registry) (Status, error) {
func pullImage(imageRef string, outputPath string, pullOptions PullOpts, reg registry.Registry) (PullStatus, error) {
plainImg := plainimage.NewPlainImage(imageRef, reg)
isImage, err := plainImg.IsImage()
if err != nil {
return Status{}, err
return PullStatus{}, err
}
if !isImage {
return Status{}, fmt.Errorf("Unable to pull non-images, such as image indexes. (hint: provide a specific digest to the image instead)")
return PullStatus{}, fmt.Errorf("Unable to pull non-images, such as image indexes. (hint: provide a specific digest to the image instead)")
}

err = plainImg.Pull(outputPath, pullOptions.Logger)
if err != nil {
return Status{}, err
return PullStatus{}, err
}
isCacheable, err := isCacheable(imageRef, true)
if err != nil {
return Status{}, err
return PullStatus{}, err
}
return Status{
return PullStatus{
BundleInfo: BundleInfo{
ImageRef: plainImg.DigestRef(),
},
Expand Down
18 changes: 9 additions & 9 deletions pkg/imgpkg/v1/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestPullImage(t *testing.T) {
}
status, err := v1.Pull(fakeRegistry.ReferenceOnTestServer(imageName)+":"+imageTag, outputFolder, opts, registry.Opts{})
require.NoError(t, err)
require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: randomImg.RefDigest,
},
Expand All @@ -69,7 +69,7 @@ func TestPullImage(t *testing.T) {
}
status, err := v1.Pull(randomImg.RefDigest, outputFolder, opts, registry.Opts{})
require.NoError(t, err)
require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: randomImg.RefDigest,
},
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestPullBundle(t *testing.T) {
}
status, err := v1.Pull(randomBundle, outputFolder, opts, registry.Opts{})
require.NoError(t, err)
require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: randomBundle,
ImagesLock: &v1.ImagesLockInfo{
Expand All @@ -161,7 +161,7 @@ func TestPullBundle(t *testing.T) {
}
status, err := v1.Pull(randomBundle, outputFolder, opts, registry.Opts{})
require.NoError(t, err)
require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: randomBundle,
},
Expand All @@ -182,7 +182,7 @@ func TestPullBundle(t *testing.T) {
}
status, err := v1.Pull(collocatedBundleRef, outputFolder, opts, registry.Opts{})
require.NoError(t, err)
require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: collocatedBundleRef,
ImagesLock: &v1.ImagesLockInfo{
Expand All @@ -208,7 +208,7 @@ func TestPullBundle(t *testing.T) {
}
status, err := v1.Pull(collocatedBundleRef, outputFolder, opts, registry.Opts{})
require.NoError(t, err)
require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: collocatedBundleRef,
},
Expand All @@ -232,7 +232,7 @@ func TestPullBundle(t *testing.T) {
}
status, err := v1.Pull(imgTag.String(), outputFolder, opts, registry.Opts{})
require.NoError(t, err)
require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: collocatedBundleRef,
},
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestPullBundleRecursively(t *testing.T) {
require.NoError(t, err)
expectedNestedBundlePath := filepath.Join(outputFolder, ".imgpkg", "bundles", fmt.Sprintf("%s-%s", hash.Algorithm, hash.Hex))

require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: bundleWithNested,
ImagesLock: &v1.ImagesLockInfo{
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestPullBundleRecursively(t *testing.T) {
require.NoError(t, err)
collocatedSimpleBundleRef := colBundleDigest.Digest(digest.DigestStr())

require.Equal(t, v1.Status{
require.Equal(t, v1.PullStatus{
BundleInfo: v1.BundleInfo{
ImageRef: collocatedBundleRef,
ImagesLock: &v1.ImagesLockInfo{
Expand Down