fix: keep all chart dependencies key / values (#2501)

* feat: Refactor TestRewriteChartDependencies

Signed-off-by: Etienne Champetier <e.champetier@ateme.com>

* fix: keep all chart dependencies key / values

In rewriteChartDependencies we were only parsing name / repository / version,
thus dropping keys like condition / import-values.

This at least fixes the use of condition.

Signed-off-by: Etienne Champetier <e.champetier@ateme.com>

---------

Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
This commit is contained in:
Etienne Champetier
2026-03-26 13:16:54 +08:00
committed by GitHub
parent 732e4ad913
commit 4bdb6f097c
12 changed files with 274 additions and 57 deletions
+1
View File
@@ -96,6 +96,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes
# TEST CASES----------------------------------------------------------------------------------------------------------
. ${dir}/test-cases/chart-deps-condition.sh
. ${dir}/test-cases/fetch-forl-local-chart.sh
. ${dir}/test-cases/suppress-output-line-regex.sh
. ${dir}/test-cases/chartify-jsonPatches-and-strategicMergePatches.sh
@@ -0,0 +1,13 @@
chart_deps_condition_input_dir="${cases_dir}/chart-deps-condition/input"
chart_deps_condition_tmp=$(mktemp -d)
actual=${chart_deps_condition_tmp}/actual.yaml
expected="${cases_dir}/chart-deps-condition/output/template"
test_start "chart with dependencies and condition"
# --concurrency 1 is a workaround for https://github.com/helmfile/helmfile/issues/2502
${helmfile} -f ${chart_deps_condition_input_dir}/helmfile.yaml template --skip-deps --concurrency 1 > ${actual} || fail "\"helmfile template\" shouldn't fail"
./dyff between -bs ${expected} ${actual} || fail "\"helmfile template\" should be consistent"
test_pass "chart with dependencies and condition"
@@ -0,0 +1,14 @@
dependencies:
- name: subchart1
repository: file://charts/subchart1
condition: subchart1.install
version: 1.0.0
- name: subchart2
repository: file://charts/subchart2
version: 2.0.0
apiVersion: v2
appVersion: 3.0.0
description: Test helm charts dependencies
name: testchartsdeps
type: application
version: 3.0.0
@@ -0,0 +1,6 @@
apiVersion: v2
name: subchart1
description: Test sub helm chart 1
type: application
version: 1.0.0
appVersion: "1.0.0"
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: testsub1
data:
sub: 1
@@ -0,0 +1,6 @@
apiVersion: v2
name: subchart2
description: Test sub helm chart 2
type: application
version: 2.0.0
appVersion: "2.0.0"
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: testsub2
data:
sub: 2
@@ -0,0 +1,2 @@
subchart1:
install: true
@@ -0,0 +1,57 @@
# Test that subcharts 'condition' is working properly
releases:
# Releases without patches, so not using chartify
- name: testdefault
chart: ./chart
namespace: testdefault
- name: testinstallfalse
chart: ./chart
namespace: testinstallfalse
values:
- subchart1:
install: false
- name: testinstalltrue
chart: ./chart
namespace: testcinstalltrue
values:
- subchart1:
install: true
# Releases with patches, so using chartify
- name: testchartifydefault
chart: ./chart
namespace: testchartifydefault
strategicMergePatches:
- apiVersion: v1
kind: ConfigMap
metadata:
name: testsub2
data:
sub: 42
- name: testchartifyinstallfalse
chart: ./chart
namespace: testchartifyinstallfalse
values:
- subchart1:
install: false
strategicMergePatches:
- apiVersion: v1
kind: ConfigMap
metadata:
name: testsub2
data:
sub: 42
- name: testchartifyinstalltrue
chart: ./chart
namespace: testchartifyinstalltrue
values:
- subchart1:
install: true
strategicMergePatches:
- apiVersion: v1
kind: ConfigMap
metadata:
name: testsub2
data:
sub: 42
@@ -0,0 +1,86 @@
---
# Source: testchartsdeps/charts/subchart1/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: testsub1
data:
sub: 1
---
# Source: testchartsdeps/charts/subchart2/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: testsub2
data:
sub: 2
---
# Source: testchartsdeps/charts/subchart2/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: testsub2
data:
sub: 2
---
# Source: testchartsdeps/charts/subchart1/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: testsub1
data:
sub: 1
---
# Source: testchartsdeps/charts/subchart2/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: testsub2
data:
sub: 2
---
# Source: testchartsdeps/templates/patched_resources.yaml
apiVersion: v1
data:
sub: 1
kind: ConfigMap
metadata:
name: testsub1
---
# Source: testchartsdeps/templates/patched_resources.yaml
apiVersion: v1
data:
sub: 42
kind: ConfigMap
metadata:
name: testsub2
---
# Source: testchartsdeps/templates/patched_resources.yaml
apiVersion: v1
data:
sub: 42
kind: ConfigMap
metadata:
name: testsub2
---
# Source: testchartsdeps/templates/patched_resources.yaml
apiVersion: v1
data:
sub: 1
kind: ConfigMap
metadata:
name: testsub1
---
# Source: testchartsdeps/templates/patched_resources.yaml
apiVersion: v1
data:
sub: 42
kind: ConfigMap
metadata:
name: testsub2