Merge pull request #6353 from mattfarina/moar-env

Environment variable cleanup
pull/6362/head
Matt Farina 6 years ago committed by GitHub
commit 24cbc33576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,7 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"sort"
"helm.sh/helm/pkg/cli" "helm.sh/helm/pkg/cli"
@ -55,8 +56,16 @@ type envOptions struct {
} }
func (o *envOptions) run(out io.Writer) error { func (o *envOptions) run(out io.Writer) error {
for _, e := range o.settings.EnvironmentVariables {
fmt.Printf("%s=\"%s\" \n", e.Name, e.Value) // Sorting keys to display in alphabetical order
var keys []string
for k := range o.settings.EnvironmentVariables {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
fmt.Printf("%s=\"%s\" \n", k, o.settings.EnvironmentVariables[k])
} }
return nil return nil
} }

@ -2,6 +2,6 @@
echo $HELM_PLUGIN_NAME echo $HELM_PLUGIN_NAME
echo $HELM_PLUGIN_DIR echo $HELM_PLUGIN_DIR
echo $HELM_PLUGIN echo $HELM_PLUGIN
echo $HELM_PATH_REPOSITORY_FILE echo $HELM_REPOSITORY_CONFIG
echo $HELM_PATH_REPOSITORY_CACHE echo $HELM_REPOSITORY_CACHE
echo $HELM_BIN echo $HELM_BIN

@ -52,13 +52,8 @@ type EnvSettings struct {
// PluginsDirectory is the path to the plugins directory. // PluginsDirectory is the path to the plugins directory.
PluginsDirectory string PluginsDirectory string
// Environment Variables Store // Environment Variables Store.
EnvironmentVariables []EnvironmentVariable EnvironmentVariables map[string]string
}
type EnvironmentVariable struct {
Name string
Value string
} }
func New() *EnvSettings { func New() *EnvSettings {
@ -67,7 +62,7 @@ func New() *EnvSettings {
RegistryConfig: helmpath.ConfigPath("registry.json"), RegistryConfig: helmpath.ConfigPath("registry.json"),
RepositoryConfig: helmpath.ConfigPath("repositories.yaml"), RepositoryConfig: helmpath.ConfigPath("repositories.yaml"),
RepositoryCache: helmpath.CachePath("repository"), RepositoryCache: helmpath.CachePath("repository"),
EnvironmentVariables: []EnvironmentVariable{}, EnvironmentVariables: make(map[string]string),
} }
envSettings.setHelmEnvVars() envSettings.setHelmEnvVars()
return &envSettings return &envSettings
@ -104,25 +99,21 @@ func setFlagFromEnv(name, envar string, fs *pflag.FlagSet) {
func (s *EnvSettings) setHelmEnvVars() { func (s *EnvSettings) setHelmEnvVars() {
for key, val := range map[string]string{ for key, val := range map[string]string{
"HELM_HOME": helmpath.DataPath(), "HELM_HOME": helmpath.DataPath(),
"HELM_PATH_STARTER": helmpath.DataPath("starters"), "HELM_PATH_STARTER": helmpath.DataPath("starters"),
"HELM_DEBUG": fmt.Sprint(s.Debug), "HELM_DEBUG": fmt.Sprint(s.Debug),
"HELM_REGISTRY_CONFIG": s.RegistryConfig, "HELM_REGISTRY_CONFIG": s.RegistryConfig,
"HELM_PATH_REPOSITORY_FILE": s.RepositoryConfig, "HELM_REPOSITORY_CONFIG": s.RepositoryConfig,
"HELM_PATH_REPOSITORY_CACHE": s.RepositoryCache, "HELM_REPOSITORY_CACHE": s.RepositoryCache,
"HELM_PLUGIN": s.PluginsDirectory, "HELM_PLUGIN": s.PluginsDirectory,
xdg.CacheHomeEnvVar: helmpath.CachePath(), xdg.CacheHomeEnvVar: helmpath.CachePath(),
xdg.ConfigHomeEnvVar: helmpath.ConfigPath(), xdg.ConfigHomeEnvVar: helmpath.ConfigPath(),
xdg.DataHomeEnvVar: helmpath.DataPath(), xdg.DataHomeEnvVar: helmpath.DataPath(),
} { } {
if eVal := os.Getenv(key); len(eVal) > 0 { if eVal := os.Getenv(key); len(eVal) > 0 {
val = eVal val = eVal
} }
s.EnvironmentVariables = append(s.EnvironmentVariables, s.EnvironmentVariables[key] = val
EnvironmentVariable{
Name: key,
Value: val,
})
} }
} }

@ -224,11 +224,12 @@ func SetupPluginEnv(settings *cli.EnvSettings, name, base string) {
"HELM_PLUGIN": settings.PluginsDirectory, "HELM_PLUGIN": settings.PluginsDirectory,
// Set vars that convey common information. // Set vars that convey common information.
"HELM_PATH_REPOSITORY_FILE": settings.RepositoryConfig, "HELM_REGISTRY_CONFIG": settings.RegistryConfig,
"HELM_PATH_REPOSITORY_CACHE": settings.RepositoryCache, "HELM_REPOSITORY_CONFIG": settings.RepositoryConfig,
"HELM_PATH_STARTER": helmpath.DataPath("starters"), "HELM_REPOSITORY_CACHE": settings.RepositoryCache,
"HELM_HOME": helmpath.DataPath(), // for backwards compatibility with Helm 2 plugins "HELM_PATH_STARTER": helmpath.DataPath("starters"),
"HELM_DEBUG": fmt.Sprint(settings.Debug), "HELM_HOME": helmpath.DataPath(), // for backwards compatibility with Helm 2 plugins
"HELM_DEBUG": fmt.Sprint(settings.Debug),
} { } {
os.Setenv(key, val) os.Setenv(key, val)
} }

Loading…
Cancel
Save