diff --git a/chartify.go b/chartify.go index 3422217..c310bb3 100644 --- a/chartify.go +++ b/chartify.go @@ -624,10 +624,15 @@ func (r *Runner) ReadAdhocDependencies(u *ChartifyOpts) ([]Dependency, error) { condName = name } + condition := d.Condition + if condition == "" { + condition = fmt.Sprintf("%s.enabled", condName) + } + deps = append(deps, Dependency{ Name: name, Repository: repoUrl, - Condition: fmt.Sprintf("%s.enabled", condName), + Condition: condition, Alias: d.Alias, Version: d.Version, }) diff --git a/chartify_test.go b/chartify_test.go index eb53096..f69abed 100644 --- a/chartify_test.go +++ b/chartify_test.go @@ -65,6 +65,45 @@ func TestReadAdhocDependencies(t *testing.T) { }, }) + run(testcase{ + opts: ChartifyOpts{ + AdhocChartDependencies: []ChartDependency{ + { + Alias: "mydb", + Chart: "./testdata/charts/db", + Condition: "global.mydb.enabled", + }, + }, + }, + wantDendency: []Dependency{ + { + Repository: "file://./testdata/charts/db", + Name: "db", + Alias: "mydb", + Condition: "global.mydb.enabled", + }, + }, + }) + + run(testcase{ + opts: ChartifyOpts{ + AdhocChartDependencies: []ChartDependency{ + { + Alias: "mydb", + Chart: "./testdata/charts/db", + }, + }, + }, + wantDendency: []Dependency{ + { + Repository: "file://./testdata/charts/db", + Name: "db", + Alias: "mydb", + Condition: "mydb.enabled", + }, + }, + }) + run(testcase{ opts: ChartifyOpts{ AdhocChartDependencies: []ChartDependency{ diff --git a/requirements.go b/requirements.go index 6a86414..ef80a2b 100644 --- a/requirements.go +++ b/requirements.go @@ -27,6 +27,9 @@ type ChartDependency struct { Alias string Chart string Version string + // Condition is written to the dependency's `condition` field. + // When empty, it defaults to `.enabled`. + Condition string } // UpdateRequirements updates either Chart.yaml's dependencies(helm 3) or requirements.yaml(helm 2)