From 79948e39fc16a68f2bfb261211437abf8e6cb555 Mon Sep 17 00:00:00 2001 From: Cayan <1619617+Cayan@users.noreply.github.com> Date: Thu, 1 Oct 2026 14:05:11 -0300 Subject: [PATCH 1/3] feat: let ad-hoc chart dependencies override their condition - ChartDependency gains an optional Condition, written to the dependency's `condition` in the generated Chart.yaml. Left empty, it keeps the current `.enabled`, so existing callers see no change. - A test covers an aliased local dependency with an explicit condition. Signed-off-by: Cayan <1619617+Cayan@users.noreply.github.com> --- chartify.go | 7 ++++++- chartify_test.go | 20 ++++++++++++++++++++ requirements.go | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) 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..539d968 100644 --- a/chartify_test.go +++ b/chartify_test.go @@ -65,6 +65,26 @@ 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{ 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) From 657670cee8eef40e74edc230763070510f009bb2 Mon Sep 17 00:00:00 2001 From: Cayan <1619617+Cayan@users.noreply.github.com> Date: Thu, 1 Oct 2026 23:35:42 -0300 Subject: [PATCH 2/3] test: default condition uses the alias over the chart name Signed-off-by: Cayan <1619617+Cayan@users.noreply.github.com> --- chartify_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/chartify_test.go b/chartify_test.go index 539d968..f69abed 100644 --- a/chartify_test.go +++ b/chartify_test.go @@ -85,6 +85,25 @@ func TestReadAdhocDependencies(t *testing.T) { }, }) + 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{ From 01264708e00e2c3c9b809634b20fc60c3c9d3a82 Mon Sep 17 00:00:00 2001 From: yxxhero Date: Tue, 20 Oct 2026 08:49:25 +0800 Subject: [PATCH 3/3] test: cover custom adhoc dependency condition end-to-end Exercise ChartDependency.Condition through the full chartify pipeline (UpdateRequirements writes it to Chart.yaml, helm template evaluates it) so the new override is proven beyond ReadAdhocDependencies unit tests. The rendered snapshots match the default-condition cases because neither the db nor the log test chart references .Values.global. Signed-off-by: yxxhero --- integration_test.go | 42 ++++++++ .../adhoc_dependency_custom_condition/want | 96 +++++++++++++++++++ .../want | 48 ++++++++++ 3 files changed, 186 insertions(+) create mode 100644 testdata/integration/testcases/adhoc_dependency_custom_condition/want create mode 100644 testdata/integration/testcases/adhoc_dependency_custom_condition_disabled/want diff --git a/integration_test.go b/integration_test.go index 565ad1a..fc71bbd 100644 --- a/integration_test.go +++ b/integration_test.go @@ -103,6 +103,48 @@ func TestIntegration(t *testing.T) { }, }) + // SAVE_SNAPSHOT=1 go1.25 test -run ^TestIntegration/adhoc_dependency_custom_condition$ ./ + // See https://github.com/helmfile/chartify/pull/214 + runTest(t, integrationTestCase{ + description: "adhoc dependency custom condition", + release: "myapp", + chart: repo + "/db", + opts: ChartifyOpts{ + AdhocChartDependencies: []ChartDependency{ + { + Alias: "log", + Chart: repo + chartSuffix, + Version: "0.1.0", + Condition: "global.log.enabled", + }, + }, + SetFlags: []string{ + "--set", "global.log.enabled=true", + }, + }, + }) + + // SAVE_SNAPSHOT=1 go1.25 test -run ^TestIntegration/adhoc_dependency_custom_condition_disabled$ ./ + // See https://github.com/helmfile/chartify/pull/214 + runTest(t, integrationTestCase{ + description: "adhoc dependency custom condition disabled", + release: "myapp", + chart: repo + "/db", + opts: ChartifyOpts{ + AdhocChartDependencies: []ChartDependency{ + { + Alias: "log", + Chart: repo + chartSuffix, + Version: "0.1.0", + Condition: "global.log.enabled", + }, + }, + SetFlags: []string{ + "--set", "global.log.enabled=false", + }, + }, + }) + // SAVE_SNAPSHOT=1 go1.25 test -run ^TestIntegration/force_namespace$ ./ runTest(t, integrationTestCase{ description: "force namespace", diff --git a/testdata/integration/testcases/adhoc_dependency_custom_condition/want b/testdata/integration/testcases/adhoc_dependency_custom_condition/want new file mode 100644 index 0000000..5311f89 --- /dev/null +++ b/testdata/integration/testcases/adhoc_dependency_custom_condition/want @@ -0,0 +1,96 @@ +--- +# Source: db/charts/log/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: myapp-log + labels: + helm.sh/chart: log-0.1.0 + app.kubernetes.io/name: log + app.kubernetes.io/instance: myapp + app.kubernetes.io/version: "1.16.0" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: log + app.kubernetes.io/instance: myapp + template: + metadata: + labels: + app.kubernetes.io/name: log + app.kubernetes.io/instance: myapp + spec: + containers: + - name: log + image: "nginx:1.16.0" +--- +# Source: db/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: myapp-db + labels: + helm.sh/chart: db-0.1.0 + app.kubernetes.io/name: db + app.kubernetes.io/instance: myapp + app.kubernetes.io/version: "1.16.0" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: db + app.kubernetes.io/instance: myapp + template: + metadata: + labels: + app.kubernetes.io/name: db + app.kubernetes.io/instance: myapp + spec: + containers: + - name: db + image: "nginx:1.16.0" +--- +# Source: db/charts/log/templates/tests/test-connection.yaml +apiVersion: v1 +kind: Pod +metadata: + name: "myapp-log-test-connection" + labels: + helm.sh/chart: log-0.1.0 + app.kubernetes.io/name: log + app.kubernetes.io/instance: myapp + app.kubernetes.io/version: "1.16.0" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['myapp-log:80'] + restartPolicy: Never +--- +# Source: db/templates/tests/test-connection.yaml +apiVersion: v1 +kind: Pod +metadata: + name: "myapp-db-test-connection" + labels: + helm.sh/chart: db-0.1.0 + app.kubernetes.io/name: db + app.kubernetes.io/instance: myapp + app.kubernetes.io/version: "1.16.0" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['myapp-db:80'] + restartPolicy: Never diff --git a/testdata/integration/testcases/adhoc_dependency_custom_condition_disabled/want b/testdata/integration/testcases/adhoc_dependency_custom_condition_disabled/want new file mode 100644 index 0000000..604ea0a --- /dev/null +++ b/testdata/integration/testcases/adhoc_dependency_custom_condition_disabled/want @@ -0,0 +1,48 @@ +--- +# Source: db/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: myapp-db + labels: + helm.sh/chart: db-0.1.0 + app.kubernetes.io/name: db + app.kubernetes.io/instance: myapp + app.kubernetes.io/version: "1.16.0" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: db + app.kubernetes.io/instance: myapp + template: + metadata: + labels: + app.kubernetes.io/name: db + app.kubernetes.io/instance: myapp + spec: + containers: + - name: db + image: "nginx:1.16.0" +--- +# Source: db/templates/tests/test-connection.yaml +apiVersion: v1 +kind: Pod +metadata: + name: "myapp-db-test-connection" + labels: + helm.sh/chart: db-0.1.0 + app.kubernetes.io/name: db + app.kubernetes.io/instance: myapp + app.kubernetes.io/version: "1.16.0" + app.kubernetes.io/managed-by: Helm + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['myapp-db:80'] + restartPolicy: Never