Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ func TestIntegration(t *testing.T) {
chart: "./testdata/charts/importvalues",
})

// SAVE_SNAPSHOT=1 go1.25 test -run ^TestIntegration/empty_render_no_op$ ./
// Tests that a chart whose templates all render to nothing (e.g. gated behind a falsy
// conditional) is treated as a no-op rather than causing an assertion error.
// See https://github.com/helmfile/chartify/issues/206
runTest(t, integrationTestCase{
description: "empty render no op",
release: "myapp",
chart: "./testdata/charts/emptychart",
opts: ChartifyOpts{
// OverrideNamespace ensures ReplaceWithRendered is called even though
// no Patches/Injectors are configured, exercising the empty-render path.
OverrideNamespace: "test-ns",
},
})

//
// Kubernets Manifests
//
Expand Down
17 changes: 17 additions & 0 deletions replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ func (r *Runner) ReplaceWithRendered(name, chartName, chartPath string, o Replac
return nil, fmt.Errorf("unable to read helm output dir entries: %w", err)
}

// When the chart renders no resources, helm template --output-dir produces an empty
// directory. Treat this as a no-op: remove original content dirs so that subsequent
// helm processing also sees no resources, clean up the temp output dir, and return
// an empty file list with no error.
if len(helmOutputDirEntries) == 0 {
if err := os.RemoveAll(helmOutputDir); err != nil {
return nil, fmt.Errorf("cleaning up empty helm output dir: %v", err)
}
for _, d := range ContentDirs {
origDir := filepath.Join(chartPath, d)
if err := os.RemoveAll(origDir); err != nil {
return nil, err
}
}
return nil, nil
}

// This directory contains templates/ and charts/SUBCHART/templates
var chartOutputDir string

Expand Down
6 changes: 6 additions & 0 deletions testdata/charts/emptychart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: emptychart
description: A Helm chart whose templates are all conditionally disabled, used to test empty render handling
type: application
version: 0.1.0
appVersion: "1.0.0"
8 changes: 8 additions & 0 deletions testdata/charts/emptychart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- if .Values.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-cm
data:
hello: world
{{- end }}
3 changes: 3 additions & 0 deletions testdata/charts/emptychart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# When enabled is false (the default), this chart renders no resources,
# which exercises the empty-render code path in chartify.
enabled: false
1 change: 1 addition & 0 deletions testdata/integration/testcases/empty_render_no_op/want
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@