Skip to content

Commit 2817b07

Browse files
fix: allow pre-v3.7.0 HELM Charts in HELM OCI Artifact downloader (#1476) (#1479)
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it The release of Helm v3.7.0 included the implementation of HIP 6 for OCI support. The chart layer media type was switched from application/tar+gzip to application/vnd.cncf.helm.chart.content.v1.tar+gzip. To support HELM Charts created before this version, we should maintain compatibility with a legacy layer detection. This implements this detection to make sure we don't have breaking changes after our recent adjustment to media type based checking. See https://helm.sh/docs/topics/registries/#oci-feature-deprecation-and-behavior-changes-with-v370 for context #### Which issue(s) this PR fixes <!-- Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> fix #1469 relates to #1470 and needs to be backported the same (cherry picked from commit 729a19f)
1 parent 78a6207 commit 2817b07

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

api/ocm/extensions/download/handlers/helm/download_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const (
3333
ArtifactType = "NotHelmChart"
3434
SpecialOCIResource = "specialhelm"
3535
UnusualOCIResource = "unusualhelm"
36+
LegacyOCIResource = "legacyhelm"
3637
)
3738

3839
var _ = Describe("upload", func() {
@@ -53,6 +54,9 @@ var _ = Describe("upload", func() {
5354
env.Resource(UnusualOCIResource, Version, resourcetypes.HELM_CHART, v1.LocalRelation, func() {
5455
env.BlobFromFile(artifactset.MediaType(artdesc.MediaTypeImageManifest), filepath.Join("/testdata/unusual-ordered-helm-chart.tgz"))
5556
})
57+
env.Resource(LegacyOCIResource, Version, resourcetypes.HELM_CHART, v1.LocalRelation, func() {
58+
env.BlobFromFile(artifactset.MediaType(artdesc.MediaTypeImageManifest), filepath.Join("/testdata/legacy-pre-hip-helm-chart.tgz"))
59+
})
5660
})
5761
})
5862
})
@@ -88,4 +92,14 @@ var _ = Describe("upload", func() {
8892
MustBeSuccessful(tarutils.ExtractArchiveToFs(env.FileSystem(), path, env.FileSystem()))
8993
Expect(Must(vfs.FileExists(env.FileSystem(), "/postgresql/Chart.yaml"))).To(BeTrue())
9094
})
95+
96+
It("successfully download artifacts with helm chart content with legacy content type", func() {
97+
MustBeSuccessful(download.RegisterHandlerByName(env, helm.PATH, nil, download.ForArtifactType(ArtifactType)))
98+
99+
repo := Must(ctf.Open(env.OCMContext(), accessobj.ACC_READONLY, CTFPath, 0o777, env))
100+
cv := Must(repo.LookupComponentVersion(Component, Version))
101+
path := Must(download.DownloadResource(env.OCMContext(), Must(cv.SelectResources(selectors.Identity(v1.Identity{"name": LegacyOCIResource})))[0], "/resource", download.WithFileSystem(env.FileSystem())))
102+
MustBeSuccessful(tarutils.ExtractArchiveToFs(env.FileSystem(), path, env.FileSystem()))
103+
Expect(Must(vfs.FileExists(env.FileSystem(), "/ingress-nginx/Chart.yaml"))).To(BeTrue())
104+
})
91105
})

api/ocm/extensions/download/handlers/helm/handler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ func download(p common.Printer, art oci.ArtifactAccess, path string, fs vfs.File
129129

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

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

0 commit comments

Comments
 (0)