From f9927e7d462e9a5c99f6aa87671d6fa17a488e4f Mon Sep 17 00:00:00 2001 From: Sunny Date: Tue, 31 Jan 2023 13:48:22 +0000 Subject: [PATCH] helm/oci: Add context to download failure Add chart address in the OCI chart download failure error message to make it clear about the chart URL that was attempted to download. Signed-off-by: Sunny --- internal/helm/chart/builder_remote_test.go | 4 ++-- internal/helm/repository/oci_chart_repository.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/helm/chart/builder_remote_test.go b/internal/helm/chart/builder_remote_test.go index c72f19d88..31e6235c5 100644 --- a/internal/helm/chart/builder_remote_test.go +++ b/internal/helm/chart/builder_remote_test.go @@ -225,7 +225,7 @@ entries: } } -func TestRemoteBuilder_BuildFromOCIChatRepository(t *testing.T) { +func TestRemoteBuilder_BuildFromOCIChartRepository(t *testing.T) { g := NewWithT(t) chartGrafana, err := os.ReadFile("./../testdata/charts/helmchart-0.1.0.tgz") @@ -293,7 +293,7 @@ func TestRemoteBuilder_BuildFromOCIChatRepository(t *testing.T) { name: "chart version not in repository", reference: RemoteReference{Name: "grafana", Version: "1.1.1"}, repository: mockRepoWithoutChart(), - wantErr: "failed to download chart for remote reference", + wantErr: "failed to download chart for remote reference: failed to get", }, { name: "invalid version metadata", diff --git a/internal/helm/repository/oci_chart_repository.go b/internal/helm/repository/oci_chart_repository.go index 08e3fc794..0e76ee0c4 100644 --- a/internal/helm/repository/oci_chart_repository.go +++ b/internal/helm/repository/oci_chart_repository.go @@ -231,7 +231,11 @@ func (r *OCIChartRepository) DownloadChart(chart *repo.ChartVersion) (*bytes.Buf defer transport.Release(t) // trim the oci scheme prefix if needed - return r.Client.Get(strings.TrimPrefix(u.String(), fmt.Sprintf("%s://", registry.OCIScheme)), clientOpts...) + b, err := r.Client.Get(strings.TrimPrefix(u.String(), fmt.Sprintf("%s://", registry.OCIScheme)), clientOpts...) + if err != nil { + return nil, fmt.Errorf("failed to get '%s': %w", ref, err) + } + return b, nil } // Login attempts to login to the OCI registry.