Process non-prefixed forms of all config settings [#9]

Trying to guess in advance which part of the config a user will put in
the `settings` section and which they'll put in `environment` is a
fool's errand. Just let everything go in either place.

The ServiceAccount field only had an `envconfig` tag (as opposed to
`split_words`) because that triggered envconfig to look for the non-
prefixed form. Now that we're finding non-prefixed forms of everything,
we can use the clearer/more concise tag.

Note that TestPopulateWithConflictingVariables isn't meant to say
"here's what behavior we *want*" so much as "here's what the behavior
*is*." I don't think one thing is any better than the other, but we
should know which one we're getting.
This commit is contained in:
Erin Call
2019-12-23 15:31:40 -08:00
parent c4c136b021
commit e2f53f3b08
2 changed files with 42 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ type Config struct {
SkipTLSVerify bool `envconfig:"SKIP_TLS_VERIFY"` // Put insecure-skip-tls-verify in .kube/config
Certificate string `envconfig:"KUBERNETES_CERTIFICATE"` // The Kubernetes cluster CA's self-signed certificate (must be base64-encoded)
APIServer string `envconfig:"API_SERVER"` // The Kubernetes cluster's API endpoint
ServiceAccount string `envconfig:"SERVICE_ACCOUNT"` // Account to use for connecting to the Kubernetes cluster
ServiceAccount string `split_words:"true"` // Account to use for connecting to the Kubernetes cluster
ChartVersion string `split_words:"true"` // Specific chart version to use in `helm upgrade`
DryRun bool `split_words:"true"` // Pass --dry-run to applicable helm commands
Wait bool `` // Pass --wait to applicable helm commands
@@ -36,7 +36,15 @@ type Config struct {
Force bool `` // Pass --force to applicable helm commands
}
// Populate reads environment variables into the Config.
// Populate reads environment variables into the Config, accounting for several possible formats.
func (cfg *Config) Populate() error {
return envconfig.Process("plugin", cfg)
if err := envconfig.Process("plugin", cfg); err != nil {
return err
}
if err := envconfig.Process("", cfg); err != nil {
return err
}
return nil
}