fix(pkg): respect subchart conditions when dependency uses an alias

When a dependency declared an alias, the nested path entry in the
coalesced values snapshot (e.g. cvals["midChart"]["leafChart"]) was
built by an ancestor's CoalesceValues call that still used the
original chart name as the map key. As a result, the subchart's own
default values were coalesced under the original name only, leaving
the alias-keyed nested entry incomplete. Condition lookups that
navigated via the accumulated path therefore returned ErrNoValue
instead of the chart's default, causing disabled-by-default
dependencies to be incorrectly rendered.

Fix by coalescing the correctly-computed top-level entry
(cvals[alias], produced at the current level after alias renaming)
into the stale nested entry before recursing. The nested entry
retains priority so explicit ancestor overrides are preserved; only
missing defaults are filled in.

Signed-off-by: Julian Siebert <j.siebert@micromata.de>
pull/31847/head
Julian Siebert 2 months ago
parent b26ec6b09e
commit 2e8f0b70cc

@ -214,6 +214,17 @@ Loop:
// recursively call self to process sub dependencies
for _, t := range cd {
// cvals[path][alias] may be stale when an alias is used, because ancestor
// CoalesceValues calls used the original chart name. Fill in missing keys from the
// correctly-coalesced top-level entry, keeping the nested entry authoritative.
if path != "" {
if pt, err := cvals.Table(strings.TrimSuffix(path, ".")); err == nil {
if top, ok := cvals[t.Metadata.Name].(map[string]interface{}); ok {
nested, _ := pt[t.Metadata.Name].(map[string]interface{})
pt[t.Metadata.Name] = util.CoalesceTables(nested, top)
}
}
}
subpath := path + t.Metadata.Name + "."
if err := processDependencyEnabled(t, cvals, subpath); err != nil {
return err

@ -134,6 +134,35 @@ func TestDependencyEnabled(t *testing.T) {
}
}
// TestDependencyEnabledAliasNestedCondition tests that a condition defaulting to false in a
// leaf chart's values.yaml is respected when the leaf chart is accessed through multiple
// levels of aliased dependencies.
func TestDependencyEnabledAliasNestedCondition(t *testing.T) {
// Chart structure:
// parentchart -> mid (alias: midchart) -> leaf (alias: leafchart) -> util (condition: util.enabled)
//
// leaf/values.yaml sets util.enabled: false.
// No user-provided values override this.
// Expected: util is NOT included in the output.
c := loadChart(t, "testdata/alias-condition-nested")
if err := processDependencyEnabled(c, c.Values, ""); err != nil {
t.Fatalf("error processing enabled dependencies: %v", err)
}
names := extractChartNames(c)
expected := []string{"parentchart", "parentchart.midchart", "parentchart.midchart.leafchart"}
sort.Strings(expected)
if len(names) != len(expected) {
t.Fatalf("slice lengths do not match: got %v, expected %v", names, expected)
}
for i := range names {
if names[i] != expected[i] {
t.Fatalf("slice values do not match: got %v, expected %v", names, expected)
}
}
}
// extractChartNames recursively searches chart dependencies returning all charts found
func extractChartNames(c *chart.Chart) []string {
var out []string

@ -0,0 +1,9 @@
apiVersion: v2
name: parentchart
version: 0.1.0
dependencies:
- name: mid
repository: http://localhost:10191
version: 0.1.0
alias: midchart
condition: midchart.enabled

@ -0,0 +1,9 @@
apiVersion: v2
name: mid
version: 0.1.0
dependencies:
- name: leaf
repository: http://localhost:10191
version: 0.1.0
alias: leafchart
condition: leafchart.enabled

@ -0,0 +1,8 @@
apiVersion: v2
name: leaf
version: 0.1.0
dependencies:
- name: util
repository: http://localhost:10191
version: 0.1.0
condition: util.enabled

@ -0,0 +1,3 @@
# util is disabled by default in this chart's values
util:
enabled: false
Loading…
Cancel
Save