Skip to content

Commit

Permalink
Merge pull request #637 from carvel-dev/fix-636
Browse files Browse the repository at this point in the history
Collect description information for images from correct registry
  • Loading branch information
joaopapereira authored Mar 4, 2024
2 parents b9bb269 + 661f271 commit e5eea31
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/imgpkg/v1/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ func (r *refWithDescription) describeBundleRec(visitedImgs map[string]refWithDes
desc.bundle.Content.Bundles[digest.DigestStr()] = bundleDesc
} else {
if ref.Error == "" {
digest, err := name.NewDigest(ref.Image)
digest, err := name.NewDigest(ref.PrimaryLocation())
if err != nil {
return desc.bundle, fmt.Errorf("Internal inconsistency: image %s should be fully resolved", ref.Image)
}
if showLayers {
layers, err = getImageLayersInfo(ref.Image)
layers, err = getImageLayersInfo(ref.PrimaryLocation())
if err != nil {
return desc.bundle, err
}
Expand Down
111 changes: 111 additions & 0 deletions test/e2e/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,4 +861,115 @@ origin: %s%s
), stdout)
})
})

t.Run("when describing relocated bundle does not reach to original images", func(t *testing.T) {
env := helpers.BuildEnv(t)
imgpkg := helpers.Imgpkg{T: t, L: helpers.Logger{}, ImgpkgPath: env.ImgpkgPath}
defer env.Cleanup()
fakeRegistryBuilder := helpers.NewFakeRegistry(t, logger)
const (
username = "some-user"
password = "some-password"
)
fakeRegistryBuilder.WithBasicAuth(username, password)
_ = fakeRegistryBuilder.Build()
defer fakeRegistryBuilder.CleanUp()

imgRef, err := regname.ParseReference(env.Image)
require.NoError(t, err)

var img1DigestRef, img1Digest string
logger.Section("create 2 simple images", func() {
img1DigestRef = fakeRegistryBuilder.ReferenceOnTestServer(imgRef.Context().RepositoryStr() + "-img1")
img1Digest = env.ImageFactory.PushSimpleAppImageWithRandomFileWithAuth(imgpkg, img1DigestRef, fakeRegistryBuilder.Host(), username, password)
img1DigestRef = img1DigestRef + img1Digest
})

privateBundle := fakeRegistryBuilder.ReferenceOnTestServer(imgRef.Context().RepositoryStr() + "-bundle")
privateBundleDigest := ""
logger.Section("create bundle", func() {
imageLockYAML := fmt.Sprintf(`---
apiVersion: imgpkg.carvel.dev/v1alpha1
kind: ImagesLock
images:
- image: %s
`, img1DigestRef)

bundleDir := env.BundleFactory.CreateBundleDir(helpers.BundleYAML, imageLockYAML)
out, err := imgpkg.RunWithOpts([]string{"push", "--tty", "-b", privateBundle, "-f", bundleDir}, helpers.RunOpts{
EnvVars: []string{
"IMGPKG_REGISTRY_HOSTNAME=" + fakeRegistryBuilder.Host(),
"IMGPKG_REGISTRY_USERNAME=" + username,
"IMGPKG_REGISTRY_PASSWORD=" + password,
},
})
require.NoError(t, err)
privateBundleDigest = fmt.Sprintf("@%s", helpers.ExtractDigest(t, out))
})

publicBundle := env.RelocationRepo
logger.Section("copy bundle to different registry", func() {
_, err := imgpkg.RunWithOpts([]string{"copy", "--tty", "-b", privateBundle + privateBundleDigest, "--to-repo", publicBundle}, helpers.RunOpts{
EnvVars: []string{
"IMGPKG_REGISTRY_HOSTNAME=" + fakeRegistryBuilder.Host(),
"IMGPKG_REGISTRY_USERNAME=" + username,
"IMGPKG_REGISTRY_PASSWORD=" + password,
},
})
require.NoError(t, err)
})

logger.Section("executes describe command", func() {
stdout := imgpkg.Run(
[]string{"describe",
"--bundle", fmt.Sprintf("%s%s", env.RelocationRepo, privateBundleDigest),
"-o", "yaml",
},
)

locationsPublicBundleImgDigest := env.ImageFactory.ImageDigest(fmt.Sprintf("%s:%s.image-locations.imgpkg", env.RelocationRepo, strings.ReplaceAll(privateBundleDigest[1:], ":", "-")))
stdoutLines := strings.Split(stdout, "\n")
stdout = strings.Join(stdoutLines[:len(stdoutLines)-1], "\n")
digestSha1 := env.ImageFactory.GetImageLayersDigest(env.RelocationRepo + img1Digest)
digestSha3 := env.ImageFactory.GetImageLayersDigest(env.RelocationRepo + "@" + locationsPublicBundleImgDigest)
digestSha4 := env.ImageFactory.GetImageLayersDigest(env.RelocationRepo + privateBundleDigest)
require.YAMLEq(t, fmt.Sprintf(`sha: %s
content:
images:
"%s":
image: %s%s
imageType: Image
layers:
- digest: %s
origin: %s
"%s":
image: %s@%s
imageType: Internal
layers:
- digest: %s
origin: %s@%s
image: %s%s
layers:
- digest: %s
metadata: {}
origin: %s%s
`,
privateBundleDigest[1:], // Bundle SHA

img1Digest[1:],
env.RelocationRepo, img1Digest,
digestSha1[0], // Image 1 Layer digest
img1DigestRef, // Origin Ref

locationsPublicBundleImgDigest,
env.RelocationRepo, locationsPublicBundleImgDigest,
digestSha3[0], // Locations Image Digest
env.RelocationRepo, locationsPublicBundleImgDigest,

env.RelocationRepo, privateBundleDigest, // Bundle Image with digest
digestSha4[0], // Bundle layer digest
env.RelocationRepo, privateBundleDigest,
), stdout)
})
})
}

0 comments on commit e5eea31

Please sign in to comment.