From 4287471accfbc88ec3794e1b434b7201b6eed9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=81uczak?= Date: Mon, 18 Nov 2024 09:35:48 +0100 Subject: [PATCH] feat: add HELMFILE_INTERACTIVE env var to enable interactive mode (#1787) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add HELMFILE_INTERACTIVE env var to enable interactive mode This commit adds the `HELMFILE_INTERACTIVE` environment variable to enable the interactive mode by default. Anything other than `true` will disable the interactive mode. The precedence has the `--interactive` flag. Signed-off-by: Krzysztof Łuczak * Trim trailing whitespaces Signed-off-by: Krzysztof Łuczak --------- Signed-off-by: Krzysztof Łuczak --- docs/index.md | 16 ++++++++++------ pkg/config/global.go | 5 ++++- pkg/envvar/const.go | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/index.md b/docs/index.md index 74b55afd..dad9f99f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -233,7 +233,7 @@ helmDefaults: deleteWait: false # Timeout is the time in seconds to wait for helmfile destroy/delete (default 300) deleteTimeout: 300 - # suppressOutputLineRegex is a list of regex patterns to suppress output lines from helm diff (default []), available in helmfile v0.162.0 + # suppressOutputLineRegex is a list of regex patterns to suppress output lines from helm diff (default []), available in helmfile v0.162.0 suppressOutputLineRegex: - "version" @@ -349,7 +349,7 @@ releases: plainHttp: false # suppressDiff skip the helm diff output. Useful for charts which produces large not helpful diff, default: false suppressDiff: false - # suppressOutputLineRegex is a list of regex patterns to suppress output lines from helm diff (default []), available in helmfile v0.162.0 + # suppressOutputLineRegex is a list of regex patterns to suppress output lines from helm diff (default []), available in helmfile v0.162.0 suppressOutputLineRegex: - "version" @@ -542,7 +542,7 @@ Helmfile uses some OS environment variables to override default behaviour: * `HELMFILE_DISABLE_INSECURE_FEATURES` - disable insecure features, expecting `true` lower case * `HELMFILE_DISABLE_RUNNER_UNIQUE_ID` - disable unique logging ID, expecting any non-empty value * `HELMFILE_SKIP_INSECURE_TEMPLATE_FUNCTIONS` - disable insecure template functions, expecting `true` lower case -* `HELMFILE_USE_HELM_STATUS_TO_CHECK_RELEASE_EXISTENCE` - expecting non-empty value to use `helm status` to check release existence, instead of `helm list` which is the default behaviour +* `HELMFILE_USE_HELM_STATUS_TO_CHECK_RELEASE_EXISTENCE` - expecting non-empty value to use `helm status` to check release existence, instead of `helm list` which is the default behaviour * `HELMFILE_EXPERIMENTAL` - enable experimental features, expecting `true` lower case * `HELMFILE_ENVIRONMENT` - specify [Helmfile environment](https://helmfile.readthedocs.io/en/latest/#environment), it has lower priority than CLI argument `--environment` * `HELMFILE_TEMPDIR` - specify directory to store temporary files @@ -550,7 +550,8 @@ Helmfile uses some OS environment variables to override default behaviour: * `HELMFILE_V1MODE` - Helmfile v0.x behaves like v1.x with `true`, Helmfile v1.x behaves like v0.x with `false` as value * `HELMFILE_GOCCY_GOYAML` - use *goccy/go-yaml* instead of *gopkg.in/yaml.v2*. It's `false` by default in Helmfile v0.x and `true` by default for Helmfile v1.x. * `HELMFILE_CACHE_HOME` - specify directory to store cached files for remote operations -* `HELMFILE_FILE_PATH` - specify the path to the helmfile.yaml file +* `HELMFILE_FILE_PATH` - specify the path to the helmfile.yaml file +* `HELMFILE_INTERACTIVE` - enable interactive mode, expecting `true` lower case. The same as `--interactive` CLI flag ## CLI Reference @@ -920,7 +921,7 @@ releases: ``` ### Environment Values -Helmfile supports 3 values languages : +Helmfile supports 3 values languages : - Straight yaml - Go templates to generate straight yaml - HCL @@ -1008,7 +1009,7 @@ HCL values supports interpolations and sharing values across files * Helmfile hcl `values` are referenced using the `hv` accessor. * Helmfile hcl `locals` are referenced using the `local` accessor. * Duplicated variables across .hcl `values` blocks are forbidden (An error will pop up specifying where are the duplicates) -* All cty [standard library functions](`https://pkg.go.dev/github.com/zclconf/go-cty@v1.14.3/cty/function/stdlib`) are available and custom functions could be created in the future +* All cty [standard library functions](`https://pkg.go.dev/github.com/zclconf/go-cty@v1.14.3/cty/function/stdlib`) are available and custom functions could be created in the future Consider the following example : @@ -1657,6 +1658,9 @@ Use it when you're running `helmfile` manually on your local machine or a kind o For your local use-case, aliasing it like `alias hi='helmfile --interactive'` would be convenient. +Another way to use it is to set the environment variable `HELMFILE_INTERACTIVE=true` to enable the interactive mode by default. +Anything other than `true` will disable the interactive mode. The precedence has the `--interactive` flag. + ## Running Helmfile without an Internet connection Once you download all required charts into your machine, you can run `helmfile sync --skip-deps` to deploy your apps. diff --git a/pkg/config/global.go b/pkg/config/global.go index d095e618..719d2132 100644 --- a/pkg/config/global.go +++ b/pkg/config/global.go @@ -246,7 +246,10 @@ func (g *GlobalImpl) ValidateConfig() error { // Interactive returns the Interactive func (g *GlobalImpl) Interactive() bool { - return g.GlobalOptions.Interactive + if g.GlobalOptions.Interactive { + return true + } + return os.Getenv(envvar.Interactive) == "true" } // Args returns the args to use for helm diff --git a/pkg/envvar/const.go b/pkg/envvar/const.go index a40f5d43..94df7381 100644 --- a/pkg/envvar/const.go +++ b/pkg/envvar/const.go @@ -18,4 +18,5 @@ const ( V1Mode = "HELMFILE_V1MODE" GoccyGoYaml = "HELMFILE_GOCCY_GOYAML" CacheHome = "HELMFILE_CACHE_HOME" + Interactive = "HELMFILE_INTERACTIVE" )