add support for HELMFILE_FILE_PATH envvar to set -f (#1255)
* fix imports Signed-off-by: Shane Starcher <shanestarcher@gmail.com> * unset env var Signed-off-by: Shane Starcher <shanestarcher@gmail.com> --------- Signed-off-by: Shane Starcher <shanestarcher@gmail.com>
This commit is contained in:
		
							parent
							
								
									4871a92b8c
								
							
						
					
					
						commit
						d681c62ff8
					
				| 
						 | 
					@ -15,6 +15,7 @@ import (
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/helmfile/helmfile/pkg/argparser"
 | 
						"github.com/helmfile/helmfile/pkg/argparser"
 | 
				
			||||||
 | 
						"github.com/helmfile/helmfile/pkg/envvar"
 | 
				
			||||||
	"github.com/helmfile/helmfile/pkg/filesystem"
 | 
						"github.com/helmfile/helmfile/pkg/filesystem"
 | 
				
			||||||
	"github.com/helmfile/helmfile/pkg/helmexec"
 | 
						"github.com/helmfile/helmfile/pkg/helmexec"
 | 
				
			||||||
	"github.com/helmfile/helmfile/pkg/plugins"
 | 
						"github.com/helmfile/helmfile/pkg/plugins"
 | 
				
			||||||
| 
						 | 
					@ -1216,7 +1217,7 @@ func (a *App) findDesiredStateFiles(specifiedPath string, opts LoadOpts) ([]stri
 | 
				
			||||||
		case defaultFile != "":
 | 
							case defaultFile != "":
 | 
				
			||||||
			return []string{defaultFile}, nil
 | 
								return []string{defaultFile}, nil
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			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)
 | 
								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 or %s environment variable", DefaultHelmfileDirectory, DefaultHelmfile, DefaultGotmplHelmfile, envvar.FilePath)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import (
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
	"golang.org/x/term"
 | 
						"golang.org/x/term"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/helmfile/helmfile/pkg/envvar"
 | 
				
			||||||
	"github.com/helmfile/helmfile/pkg/maputil"
 | 
						"github.com/helmfile/helmfile/pkg/maputil"
 | 
				
			||||||
	"github.com/helmfile/helmfile/pkg/state"
 | 
						"github.com/helmfile/helmfile/pkg/state"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -120,7 +121,12 @@ func (g *GlobalImpl) Chart() string {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FileOrDir returns the path to the Helmfile.
 | 
					// FileOrDir returns the path to the Helmfile.
 | 
				
			||||||
func (g *GlobalImpl) FileOrDir() string {
 | 
					func (g *GlobalImpl) FileOrDir() string {
 | 
				
			||||||
	return g.GlobalOptions.File
 | 
						file := g.GlobalOptions.File
 | 
				
			||||||
 | 
						if file == "" {
 | 
				
			||||||
 | 
							file = os.Getenv(envvar.FilePath)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return file
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Selectors returns the selectors to use.
 | 
					// Selectors returns the selectors to use.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,47 @@
 | 
				
			||||||
 | 
					package config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/require"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/helmfile/helmfile/pkg/envvar"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TestFileOrDir tests if statement
 | 
				
			||||||
 | 
					func TestFileOrDir(t *testing.T) {
 | 
				
			||||||
 | 
						tests := []struct {
 | 
				
			||||||
 | 
							opts     GlobalOptions
 | 
				
			||||||
 | 
							env      string
 | 
				
			||||||
 | 
							expected string
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								opts:     GlobalOptions{},
 | 
				
			||||||
 | 
								env:      "",
 | 
				
			||||||
 | 
								expected: "",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								opts:     GlobalOptions{},
 | 
				
			||||||
 | 
								env:      "envset",
 | 
				
			||||||
 | 
								expected: "envset",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								opts:     GlobalOptions{File: "folderset"},
 | 
				
			||||||
 | 
								env:      "",
 | 
				
			||||||
 | 
								expected: "folderset",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								opts:     GlobalOptions{File: "folderset"},
 | 
				
			||||||
 | 
								env:      "envset",
 | 
				
			||||||
 | 
								expected: "folderset",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, test := range tests {
 | 
				
			||||||
 | 
							os.Setenv(envvar.FilePath, test.env)
 | 
				
			||||||
 | 
							received := NewGlobalImpl(&test.opts).FileOrDir()
 | 
				
			||||||
 | 
							require.Equalf(t, test.expected, received, "FileOrDir expected %t, received %t", test.expected, received)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						os.Unsetenv(envvar.FilePath)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,7 @@ const (
 | 
				
			||||||
	SkipInsecureTemplateFunctions = "HELMFILE_SKIP_INSECURE_TEMPLATE_FUNCTIONS"
 | 
						SkipInsecureTemplateFunctions = "HELMFILE_SKIP_INSECURE_TEMPLATE_FUNCTIONS"
 | 
				
			||||||
	Experimental                  = "HELMFILE_EXPERIMENTAL" // environment variable for experimental features, expecting "true" lower case
 | 
						Experimental                  = "HELMFILE_EXPERIMENTAL" // environment variable for experimental features, expecting "true" lower case
 | 
				
			||||||
	Environment                   = "HELMFILE_ENVIRONMENT"
 | 
						Environment                   = "HELMFILE_ENVIRONMENT"
 | 
				
			||||||
 | 
						FilePath                      = "HELMFILE_FILE_PATH"
 | 
				
			||||||
	TempDir                       = "HELMFILE_TEMPDIR"
 | 
						TempDir                       = "HELMFILE_TEMPDIR"
 | 
				
			||||||
	UpgradeNoticeDisabled         = "HELMFILE_UPGRADE_NOTICE_DISABLED"
 | 
						UpgradeNoticeDisabled         = "HELMFILE_UPGRADE_NOTICE_DISABLED"
 | 
				
			||||||
	V1Mode                        = "HELMFILE_V1MODE"
 | 
						V1Mode                        = "HELMFILE_V1MODE"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue