From eb8ab54865470002ae919feac45a2897967f5d8b Mon Sep 17 00:00:00 2001 From: Craig Furman Date: Tue, 12 May 2020 01:41:39 +0100 Subject: [PATCH] Optionally error when subhelmfiles do not exist (#1245) This prevents typos in helmfiles from silently preventing operations from running. The default behavior is to print a warning, to preserve backwards compatibility. --- README.md | 3 +++ pkg/state/state.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 08c20d74..c89346e1 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,9 @@ helmfiles: # The nested-state file is locally checked-out along with the remote directory containing it. # Therefore all the local paths in the file are resolved relative to the file path: git::https://github.com/cloudposse/helmfiles.git@releases/kiam.yaml?ref=0.40.0 +# If set to "Error", return an error when a subhelmfile points to a +# non-existent path. The default behavior is to print a warning and continue. +missingFileHandler: Error # # Advanced Configuration: Environments diff --git a/pkg/state/state.go b/pkg/state/state.go index 5ca00b73..43498079 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -73,6 +73,11 @@ type HelmState struct { runner helmexec.Runner valsRuntime vals.Evaluator + + // If set to "Error", return an error when a subhelmfile points to a + // non-existent path. The default behavior is to print a warning. Note the + // differing default compared to other MissingFileHandlers. + MissingFileHandler string `yaml:"missingFileHandler"` } // SubHelmfileSpec defines the subhelmfile path and options @@ -1801,6 +1806,11 @@ func (st *HelmState) ExpandedHelmfiles() ([]SubHelmfileSpec, error) { return nil, err } if len(matches) == 0 { + err := fmt.Errorf("no matches for path: %s", hf.Path) + if st.MissingFileHandler == "Error" { + return nil, err + } + fmt.Println(err) continue } for _, match := range matches {