From 6b5d0b1335902c7a395a8f9573f123ac64a69ea7 Mon Sep 17 00:00:00 2001 From: Soule BA Date: Fri, 16 Dec 2022 16:07:06 +0100 Subject: [PATCH] Fix aliased chart dependencies resolution If implemented, this fix the issue were aliased chart dependencies were detected but not included in the final packaged chart. Signed-off-by: Soule BA --- controllers/helmchart_controller_test.go | 6 ++++++ internal/helm/chart/dependency_manager.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/controllers/helmchart_controller_test.go b/controllers/helmchart_controller_test.go index 6f6bb0ddb..cd71e1e85 100644 --- a/controllers/helmchart_controller_test.go +++ b/controllers/helmchart_controller_test.go @@ -60,6 +60,7 @@ import ( sourcev1 "github.com/fluxcd/source-controller/api/v1beta2" serror "github.com/fluxcd/source-controller/internal/error" "github.com/fluxcd/source-controller/internal/helm/chart" + "github.com/fluxcd/source-controller/internal/helm/chart/secureloader" "github.com/fluxcd/source-controller/internal/helm/registry" "github.com/fluxcd/source-controller/internal/oci" sreconcile "github.com/fluxcd/source-controller/internal/reconcile" @@ -1159,6 +1160,11 @@ func TestHelmChartReconciler_buildFromTarballArtifact(t *testing.T) { g.Expect(build.Version).To(Equal("0.1.0")) g.Expect(build.ResolvedDependencies).To(Equal(4)) g.Expect(build.Path).To(BeARegularFile()) + chart, err := secureloader.LoadFile(build.Path) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(chart.Metadata.Name).To(Equal("helmchartwithdeps")) + g.Expect(chart.Metadata.Version).To(Equal("0.1.0")) + g.Expect(chart.Dependencies()).To(HaveLen(4)) }, cleanFunc: func(g *WithT, build *chart.Build) { g.Expect(os.Remove(build.Path)).To(Succeed()) diff --git a/internal/helm/chart/dependency_manager.go b/internal/helm/chart/dependency_manager.go index 1fbe6328c..4465931c7 100644 --- a/internal/helm/chart/dependency_manager.go +++ b/internal/helm/chart/dependency_manager.go @@ -218,6 +218,10 @@ func (dm *DependencyManager) addLocalDependency(ref LocalReference, c *chartWith return err } + if dep.Alias != "" { + ch.Metadata.Name = dep.Alias + } + c.mu.Lock() c.AddDependency(ch) c.mu.Unlock() @@ -246,6 +250,10 @@ func (dm *DependencyManager) addRemoteDependency(chart *chartWithLock, dep *helm return fmt.Errorf("failed to load downloaded archive of version '%s': %w", ver.Version, err) } + if dep.Alias != "" { + ch.Metadata.Name = dep.Alias + } + chart.mu.Lock() chart.AddDependency(ch) chart.mu.Unlock()