Skip to content
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
14 changes: 14 additions & 0 deletions api/ocm/extensions/download/handlers/helm/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
ArtifactType = "NotHelmChart"
SpecialOCIResource = "specialhelm"
UnusualOCIResource = "unusualhelm"
LegacyOCIResource = "legacyhelm"
)

var _ = Describe("upload", func() {
Expand All @@ -53,6 +54,9 @@ var _ = Describe("upload", func() {
env.Resource(UnusualOCIResource, Version, resourcetypes.HELM_CHART, v1.LocalRelation, func() {
env.BlobFromFile(artifactset.MediaType(artdesc.MediaTypeImageManifest), filepath.Join("/testdata/unusual-ordered-helm-chart.tgz"))
})
env.Resource(LegacyOCIResource, Version, resourcetypes.HELM_CHART, v1.LocalRelation, func() {
env.BlobFromFile(artifactset.MediaType(artdesc.MediaTypeImageManifest), filepath.Join("/testdata/legacy-pre-hip-helm-chart.tgz"))
})
})
})
})
Expand Down Expand Up @@ -88,4 +92,14 @@ var _ = Describe("upload", func() {
MustBeSuccessful(tarutils.ExtractArchiveToFs(env.FileSystem(), path, env.FileSystem()))
Expect(Must(vfs.FileExists(env.FileSystem(), "/postgresql/Chart.yaml"))).To(BeTrue())
})

It("successfully download artifacts with helm chart content with legacy content type", func() {
MustBeSuccessful(download.RegisterHandlerByName(env, helm.PATH, nil, download.ForArtifactType(ArtifactType)))

repo := Must(ctf.Open(env.OCMContext(), accessobj.ACC_READONLY, CTFPath, 0o777, env))
cv := Must(repo.LookupComponentVersion(Component, Version))
path := Must(download.DownloadResource(env.OCMContext(), Must(cv.SelectResources(selectors.Identity(v1.Identity{"name": LegacyOCIResource})))[0], "/resource", download.WithFileSystem(env.FileSystem())))
MustBeSuccessful(tarutils.ExtractArchiveToFs(env.FileSystem(), path, env.FileSystem()))
Expect(Must(vfs.FileExists(env.FileSystem(), "/ingress-nginx/Chart.yaml"))).To(BeTrue())
})
})
7 changes: 6 additions & 1 deletion api/ocm/extensions/download/handlers/helm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ func download(p common.Printer, art oci.ArtifactAccess, path string, fs vfs.File

chartDesc, err := findLayer(desc.Layers, helmregistry.ChartLayerMediaType)
if err != nil {
return "", "", fmt.Errorf("no valid chart layer found: %w", err)
// Fallback to legacy chart layer media type if no chart layer is found in the normal order.
// See https://helm.sh/docs/topics/registries/#oci-feature-deprecation-and-behavior-changes-with-v370
var fallbackErr error
if chartDesc, fallbackErr = findLayer(desc.Layers, helmregistry.LegacyChartLayerMediaType); fallbackErr != nil {
return "", "", errors.Join(err, fallbackErr)
}
}

chartBlob, err := m.GetBlob(chartDesc.Digest)
Expand Down
Binary file not shown.