diff --git a/pkg/app/app.go b/pkg/app/app.go index 79f1786e..9a8a64a1 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -3,7 +3,6 @@ package app import ( "bytes" "fmt" - "log" "os" "path/filepath" "sort" @@ -1159,12 +1158,20 @@ func (a *App) findDesiredStateFiles(specifiedPath string, opts LoadOpts) ([]stri } } else { var defaultFile string - if a.fs.FileExistsAt(DefaultHelmfile) { + DefaultGotmplHelmfile := DefaultHelmfile + ".gotmpl" + if a.fs.FileExistsAt(DefaultHelmfile) && a.fs.FileExistsAt(DefaultGotmplHelmfile) { + return []string{}, fmt.Errorf("both %s and %s.gotmpl exist. Please remove one of them", DefaultHelmfile, DefaultHelmfile) + } + switch { + case a.fs.FileExistsAt(DefaultHelmfile): defaultFile = DefaultHelmfile - // TODO: Remove this block when we remove v0 code - } else if !runtime.V1Mode && a.fs.FileExistsAt(DeprecatedHelmfile) { - log.Printf( + case a.fs.FileExistsAt(DefaultGotmplHelmfile): + defaultFile = DefaultGotmplHelmfile + + // TODO: Remove this block when we remove v0 code + case !runtime.V1Mode && a.fs.FileExistsAt(DeprecatedHelmfile): + a.Logger.Warnf( "warn: %s is being loaded: %s is deprecated in favor of %s. See https://github.com/roboll/helmfile/issues/25 for more information", DeprecatedHelmfile, DeprecatedHelmfile, @@ -1183,14 +1190,24 @@ func (a *App) findDesiredStateFiles(specifiedPath string, opts LoadOpts) ([]stri case defaultFile != "": return []string{defaultFile}, nil default: - return []string{}, fmt.Errorf("no state file found. It must be named %s/*.{yaml,yml} or %s, otherwise specified with the --file flag", DefaultHelmfileDirectory, DefaultHelmfile) + return []string{}, fmt.Errorf("no state file found. It must be named %s/*.{yaml,yml,yaml.gotmpl,yml.gotmpl}, %s, or %s, otherwise specified with the --file flag", DefaultHelmfileDirectory, DefaultHelmfile, DefaultGotmplHelmfile) } } - files, err := a.fs.Glob(filepath.Join(helmfileDir, "*.y*ml")) + files := []string{} + + ymlFiles, err := a.fs.Glob(filepath.Join(helmfileDir, "*.y*ml")) if err != nil { return []string{}, err } + gotmplFiles, err := a.fs.Glob(filepath.Join(helmfileDir, "*.y*ml.gotmpl")) + if err != nil { + return []string{}, err + } + + files = append(files, ymlFiles...) + files = append(files, gotmplFiles...) + if opts.Reverse { sort.Slice(files, func(i, j int) bool { return files[j] < files[i] @@ -1200,6 +1217,9 @@ func (a *App) findDesiredStateFiles(specifiedPath string, opts LoadOpts) ([]stri return files[i] < files[j] }) } + + a.Logger.Debugf("found %d helmfile state files in %s: %s", len(ymlFiles)+len(gotmplFiles), helmfileDir, strings.Join(files, ", ")) + return files, nil } diff --git a/pkg/app/testdata/app_list_test/default_environment_includes_all_releases b/pkg/app/testdata/app_list_test/default_environment_includes_all_releases index f9682de0..a2ecd2b5 100644 --- a/pkg/app/testdata/app_list_test/default_environment_includes_all_releases +++ b/pkg/app/testdata/app_list_test/default_environment_includes_all_releases @@ -1,3 +1,4 @@ +found 3 helmfile state files in helmfile.d: /path/to/helmfile.d/helmfile_1.yaml, /path/to/helmfile.d/helmfile_2.yaml, /path/to/helmfile.d/helmfile_3.yaml processing file "helmfile_1.yaml" in directory "/path/to/helmfile.d" changing working directory to "/path/to/helmfile.d" first-pass rendering starting for "helmfile_1.yaml.part.0": inherited=&{default map[] map[]}, overrode= diff --git a/pkg/app/testdata/app_list_test/fail_on_unknown_environment b/pkg/app/testdata/app_list_test/fail_on_unknown_environment index ca68355a..5f4b2add 100644 --- a/pkg/app/testdata/app_list_test/fail_on_unknown_environment +++ b/pkg/app/testdata/app_list_test/fail_on_unknown_environment @@ -1,3 +1,4 @@ +found 3 helmfile state files in helmfile.d: /path/to/helmfile.d/helmfile_1.yaml, /path/to/helmfile.d/helmfile_2.yaml, /path/to/helmfile.d/helmfile_3.yaml processing file "helmfile_1.yaml" in directory "/path/to/helmfile.d" changing working directory to "/path/to/helmfile.d" first-pass rendering starting for "helmfile_1.yaml.part.0": inherited=&{staging map[] map[]}, overrode= diff --git a/pkg/app/testdata/app_list_test/filters_releases_for_environment_used_in_multiple_files b/pkg/app/testdata/app_list_test/filters_releases_for_environment_used_in_multiple_files index 0202a4b8..8a0fb275 100644 --- a/pkg/app/testdata/app_list_test/filters_releases_for_environment_used_in_multiple_files +++ b/pkg/app/testdata/app_list_test/filters_releases_for_environment_used_in_multiple_files @@ -1,3 +1,4 @@ +found 3 helmfile state files in helmfile.d: /path/to/helmfile.d/helmfile_1.yaml, /path/to/helmfile.d/helmfile_2.yaml, /path/to/helmfile.d/helmfile_3.yaml processing file "helmfile_1.yaml" in directory "/path/to/helmfile.d" changing working directory to "/path/to/helmfile.d" first-pass rendering starting for "helmfile_1.yaml.part.0": inherited=&{shared map[] map[]}, overrode= diff --git a/pkg/app/testdata/app_list_test/filters_releases_for_environment_used_in_one_file_only b/pkg/app/testdata/app_list_test/filters_releases_for_environment_used_in_one_file_only index 402abbe2..32e2cac9 100644 --- a/pkg/app/testdata/app_list_test/filters_releases_for_environment_used_in_one_file_only +++ b/pkg/app/testdata/app_list_test/filters_releases_for_environment_used_in_one_file_only @@ -1,3 +1,4 @@ +found 3 helmfile state files in helmfile.d: /path/to/helmfile.d/helmfile_1.yaml, /path/to/helmfile.d/helmfile_2.yaml, /path/to/helmfile.d/helmfile_3.yaml processing file "helmfile_1.yaml" in directory "/path/to/helmfile.d" changing working directory to "/path/to/helmfile.d" first-pass rendering starting for "helmfile_1.yaml.part.0": inherited=&{test map[] map[]}, overrode= diff --git a/pkg/app/testdata/app_list_test/list_releases_matching_selector_and_environment b/pkg/app/testdata/app_list_test/list_releases_matching_selector_and_environment index 2d498ce0..af5b8dc5 100644 --- a/pkg/app/testdata/app_list_test/list_releases_matching_selector_and_environment +++ b/pkg/app/testdata/app_list_test/list_releases_matching_selector_and_environment @@ -1,3 +1,4 @@ +found 3 helmfile state files in helmfile.d: /path/to/helmfile.d/helmfile_1.yaml, /path/to/helmfile.d/helmfile_2.yaml, /path/to/helmfile.d/helmfile_3.yaml processing file "helmfile_1.yaml" in directory "/path/to/helmfile.d" changing working directory to "/path/to/helmfile.d" first-pass rendering starting for "helmfile_1.yaml.part.0": inherited=&{development map[] map[]}, overrode=