From faf84d1fcf05c42eb97b8448cf1ad89e29a6a339 Mon Sep 17 00:00:00 2001 From: Jonas Lergell Date: Sun, 21 Nov 2021 12:00:53 +0100 Subject: [PATCH] Proposed solution for sub sub chart alias bug Signed-off-by: Jonas Lergell --- pkg/chart/dependency.go | 17 +++++++++++++++++ pkg/chartutil/dependencies.go | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/chart/dependency.go b/pkg/chart/dependency.go index b2819f373..36ac4aad9 100644 --- a/pkg/chart/dependency.go +++ b/pkg/chart/dependency.go @@ -47,6 +47,23 @@ type Dependency struct { ImportValues []interface{} `json:"import-values,omitempty"` // Alias usable alias to be used for the chart Alias string `json:"alias,omitempty"` + + originalName string +} + +// SetNameFromAlias sets originalName if empty, so can be called multiple times. +// This assumes that the first time SetNameFromAlias is called, d.Name is the name as +// specified in the dependency's Chart.yaml +func (d *Dependency) SetNameFromAlias() { + if d.originalName == "" { + d.originalName = d.Name + } + d.Name = d.Alias +} + +// EqualName returns true if the dependency's name or originalName is equal to the given name. +func (d *Dependency) EqualName(name string) bool { + return d.Name == name || d.originalName == name } // Validate checks for common problems with the dependency datastructure in diff --git a/pkg/chartutil/dependencies.go b/pkg/chartutil/dependencies.go index d2e7d6dc9..e3ae4c9d4 100644 --- a/pkg/chartutil/dependencies.go +++ b/pkg/chartutil/dependencies.go @@ -95,7 +95,7 @@ func getAliasDependency(charts []*chart.Chart, dep *chart.Dependency) *chart.Cha if c == nil { continue } - if c.Name() != dep.Name { + if !dep.EqualName(c.Name()) { continue } if !IsCompatibleRange(dep.Version, c.Metadata.Version) { @@ -129,7 +129,7 @@ func processDependencyEnabled(c *chart.Chart, v map[string]interface{}, path str Loop: for _, existing := range c.Dependencies() { for _, req := range c.Metadata.Dependencies { - if existing.Name() == req.Name && IsCompatibleRange(req.Version, existing.Metadata.Version) { + if req.EqualName(existing.Name()) && IsCompatibleRange(req.Version, existing.Metadata.Version) { continue Loop } } @@ -141,7 +141,7 @@ Loop: chartDependencies = append(chartDependencies, chartDependency) } if req.Alias != "" { - req.Name = req.Alias + req.SetNameFromAlias() } } c.SetDependencies(chartDependencies...)