Skip to content

Commit

Permalink
Merge pull request #635 from carvel-dev/fix-464
Browse files Browse the repository at this point in the history
Fix DiffID check when layers do not have them
  • Loading branch information
joaopapereira authored Feb 21, 2024
2 parents a214d12 + c8cece2 commit 3056c35
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/imgpkg/imagedesc/image_ref_descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,16 @@ func (ids *ImageRefDescriptors) buildImage(ref Metadata) (ImageDescriptor, error
if err != nil {
return td, err
}
layerDiffID, err := layer.DiffID()
if err != nil {
return td, err

layerDiffID := ""
if layerMediaType.IsLayer() {
lDiffID, err := layer.DiffID()
if err != nil {
return td, err
}
layerDiffID = lDiffID.String()
}

layerSize, err := layer.Size()
if err != nil {
return td, err
Expand All @@ -234,7 +240,7 @@ func (ids *ImageRefDescriptors) buildImage(ref Metadata) (ImageDescriptor, error
layerTD := ImageLayerDescriptor{
MediaType: string(layerMediaType),
Digest: layerDigest.String(),
DiffID: layerDiffID.String(),
DiffID: layerDiffID,
Size: layerSize,
}

Expand Down
Binary file added test/e2e/assets/helm-chart.tar
Binary file not shown.
20 changes: 20 additions & 0 deletions test/e2e/copy_from_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,26 @@ func TestCopyRepoToTarAndThenCopyFromTarToRepo(t *testing.T) {
})
}

func TestCopyImageWithLayersThatDoNotFollowSpec(t *testing.T) {
const helmChartSHA = "sha256:f247f3b9467b611bc970d14d890b0f65b1128786f1bbb4712bc02fa59f58f9f8"
env := helpers.BuildEnv(t)
imgpkg := helpers.Imgpkg{T: t, L: helpers.Logger{}, ImgpkgPath: env.ImgpkgPath}
defer env.Cleanup()

logger := helpers.Logger{}
tag := time.Now().UnixNano()

logger.Section(fmt.Sprintf("Copy tar of helm chart to the registry '%d'", tag), func() {
imgpkg.Run([]string{"copy", "--tar", "./assets/helm-chart.tar",
"--to-repo", env.RelocationRepo})
})

logger.Section("Copy Image using the Tag", func() {
imgpkg.Run([]string{"copy", "--image", fmt.Sprintf("%s@%v", env.RelocationRepo, helmChartSHA),
"--to-repo", env.RelocationRepo + "-1"})
})
}

func TestCopyErrors(t *testing.T) {
logger := helpers.Logger{}
t.Run("When copying an Image using the -b flag", func(t *testing.T) {
Expand Down

0 comments on commit 3056c35

Please sign in to comment.