Merge pull request #4917 from derkoe/dev-v3-fix-requirement-condition

fix(pkg/chartutil): conditions for alias and umrella charts (#3734)
pull/6549/head
Matthew Fisher 5 years ago committed by GitHub
commit 37f7cc0851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,14 +24,14 @@ import (
// ProcessDependencies checks through this chart's dependencies, processing accordingly.
func ProcessDependencies(c *chart.Chart, v Values) error {
if err := processDependencyEnabled(c, v); err != nil {
if err := processDependencyEnabled(c, v, ""); err != nil {
return err
}
return processDependencyImportValues(c)
}
// processDependencyConditions disables charts based on condition path value in values
func processDependencyConditions(reqs []*chart.Dependency, cvals Values) {
func processDependencyConditions(reqs []*chart.Dependency, cvals Values, cpath string) {
if reqs == nil {
return
}
@ -40,7 +40,7 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals Values) {
for _, c := range strings.Split(strings.TrimSpace(r.Condition), ",") {
if len(c) > 0 {
// retrieve value
vv, err := cvals.PathValue(c)
vv, err := cvals.PathValue(cpath + c)
if err == nil {
// if not bool, warn
if bv, ok := vv.(bool); ok {
@ -129,7 +129,7 @@ func getAliasDependency(charts []*chart.Chart, dep *chart.Dependency) *chart.Cha
}
// processDependencyEnabled removes disabled charts from dependencies
func processDependencyEnabled(c *chart.Chart, v map[string]interface{}) error {
func processDependencyEnabled(c *chart.Chart, v map[string]interface{}, path string) error {
if c.Metadata.Dependencies == nil {
return nil
}
@ -170,7 +170,7 @@ Loop:
}
// flag dependencies as enabled/disabled
processDependencyTags(c.Metadata.Dependencies, cvals)
processDependencyConditions(c.Metadata.Dependencies, cvals)
processDependencyConditions(c.Metadata.Dependencies, cvals, path)
// make a map of charts to remove
rm := map[string]struct{}{}
for _, r := range c.Metadata.Dependencies {
@ -190,7 +190,8 @@ Loop:
// recursively call self to process sub dependencies
for _, t := range cd {
if err := processDependencyEnabled(t, cvals); err != nil {
subpath := path + t.Metadata.Name + "."
if err := processDependencyEnabled(t, cvals, subpath); err != nil {
return err
}
}

@ -101,18 +101,22 @@ func TestDependencyEnabled(t *testing.T) {
[]string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subchartb"},
}, {
"tags enabling a parent/child group with condition disabling one child",
M{"subchartc": M{"enabled": false}, "tags": M{"back-end": true}},
M{"subchart2": M{"subchartc": M{"enabled": false}}, "tags": M{"back-end": true}},
[]string{"parentchart", "parentchart.subchart1", "parentchart.subchart1.subcharta", "parentchart.subchart1.subchartb", "parentchart.subchart2", "parentchart.subchart2.subchartb"},
}, {
"tags will not enable a child if parent is explicitly disabled with condition",
M{"subchart1": M{"enabled": false}, "tags": M{"front-end": true}},
[]string{"parentchart"},
}, {
"subcharts with alias also respect conditions",
M{"subchart1": M{"enabled": false}, "subchart2alias": M{"enabled": true, "subchartb": M{"enabled": true}}},
[]string{"parentchart", "parentchart.subchart2alias", "parentchart.subchart2alias.subchartb"},
}}
for _, tc := range tests {
c := loadChart(t, "testdata/subpop")
t.Run(tc.name, func(t *testing.T) {
if err := processDependencyEnabled(c, tc.v); err != nil {
if err := processDependencyEnabled(c, tc.v, ""); err != nil {
t.Fatalf("error processing enabled dependencies %v", err)
}
@ -281,7 +285,7 @@ func TestDependentChartAliases(t *testing.T) {
t.Fatalf("expected 2 dependencies for this chart, but got %d", len(c.Dependencies()))
}
if err := processDependencyEnabled(c, c.Values); err != nil {
if err := processDependencyEnabled(c, c.Values, ""); err != nil {
t.Fatalf("expected no errors but got %q", err)
}
@ -302,7 +306,7 @@ func TestDependentChartWithSubChartsAbsentInDependency(t *testing.T) {
t.Fatalf("expected 2 dependencies for this chart, but got %d", len(c.Dependencies()))
}
if err := processDependencyEnabled(c, c.Values); err != nil {
if err := processDependencyEnabled(c, c.Values, ""); err != nil {
t.Fatalf("expected no errors but got %q", err)
}
@ -339,7 +343,7 @@ func TestDependentChartsWithSubchartsAllSpecifiedInDependency(t *testing.T) {
t.Fatalf("expected 2 dependencies for this chart, but got %d", len(c.Dependencies()))
}
if err := processDependencyEnabled(c, c.Values); err != nil {
if err := processDependencyEnabled(c, c.Values, ""); err != nil {
t.Fatalf("expected no errors but got %q", err)
}
@ -359,7 +363,7 @@ func TestDependentChartsWithSomeSubchartsSpecifiedInDependency(t *testing.T) {
t.Fatalf("expected 2 dependencies for this chart, but got %d", len(c.Dependencies()))
}
if err := processDependencyEnabled(c, c.Values); err != nil {
if err := processDependencyEnabled(c, c.Values, ""); err != nil {
t.Fatalf("expected no errors but got %q", err)
}

@ -33,3 +33,9 @@ dependencies:
tags:
- back-end
- subchart2
- name: subchart2
alias: subchart2alias
repository: http://localhost:10191
version: 0.1.0
condition: subchart2alias.enabled

@ -6,7 +6,7 @@ dependencies:
- name: subcharta
repository: http://localhost:10191
version: 0.1.0
condition: subcharta.enabled,subchart1.subcharta.enabled
condition: subcharta.enabled
tags:
- front-end
- subcharta

@ -6,7 +6,7 @@ dependencies:
- name: subchartb
repository: http://localhost:10191
version: 0.1.0
condition: subchartb.enabled,subchart2.subchartb.enabled
condition: subchartb.enabled
tags:
- back-end
- subchartb

@ -38,3 +38,6 @@ overridden-chartA-B:
tags:
front-end: true
back-end: false
subchart2alias:
enabled: false

Loading…
Cancel
Save