Use "kube" in setting aliases [#66]

Nobody likes typing "kubernetes"! Writing out that whole word without
typos is the third hard problem in computer science.
This commit is contained in:
Erin Call 2020-01-07 15:39:05 -08:00
parent 04de280821
commit 1d1117ba49
No known key found for this signature in database
GPG key ID: 4071FF6C15B8DAD1
2 changed files with 18 additions and 4 deletions

View file

@ -87,6 +87,12 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
if aliases.Force != nil {
cfg.Force = *aliases.Force
}
if aliases.KubeToken != nil {
cfg.KubeToken = *aliases.KubeToken
}
if aliases.Certificate != nil {
cfg.Certificate = *aliases.Certificate
}
if justNumbers.MatchString(cfg.Timeout) {
cfg.Timeout = fmt.Sprintf("%ss", cfg.Timeout)
@ -121,8 +127,10 @@ func (cfg *Config) deprecationWarn() {
type settingAliases struct {
Command *string `envconfig:"mode"`
AddRepos *[]string `envconfig:"add_repos"`
APIServer *string `envconfig:"kubernetes_api_server"`
ServiceAccount *string `envconfig:"kubernetes_service_account"`
APIServer *string `envconfig:"kube_api_server"`
ServiceAccount *string `envconfig:"kube_service_account"`
Wait *bool `envconfig:"wait_for_upgrade"`
Force *bool `envconfig:"force_upgrade"`
KubeToken *string `envconfig:"kube_token"`
Certificate *string `envconfig:"kube_certificate"`
}

View file

@ -78,16 +78,20 @@ func (suite *ConfigTestSuite) TestNewConfigWithAliases() {
"SERVICE_ACCOUNT",
"WAIT",
"FORCE",
"KUBERNETES_TOKEN",
"KUBERNETES_CERTIFICATE",
} {
suite.unsetenv(varname)
suite.unsetenv("PLUGIN_" + varname)
}
suite.setenv("PLUGIN_MODE", "iambic")
suite.setenv("PLUGIN_ADD_REPOS", "chortle=http://calloo.callay/frabjous/day")
suite.setenv("PLUGIN_KUBERNETES_API_SERVER", "http://tumtum.tree")
suite.setenv("PLUGIN_KUBERNETES_SERVICE_ACCOUNT", "tulgey")
suite.setenv("PLUGIN_KUBE_API_SERVER", "http://tumtum.tree")
suite.setenv("PLUGIN_KUBE_SERVICE_ACCOUNT", "tulgey")
suite.setenv("PLUGIN_WAIT_FOR_UPGRADE", "true")
suite.setenv("PLUGIN_FORCE_UPGRADE", "true")
suite.setenv("PLUGIN_KUBE_TOKEN", "Y29tZSB0byBteSBhcm1z")
suite.setenv("PLUGIN_KUBE_CERTIFICATE", "d2l0aCBpdHMgaGVhZA==")
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
suite.Require().NoError(err)
@ -97,6 +101,8 @@ func (suite *ConfigTestSuite) TestNewConfigWithAliases() {
suite.Equal("tulgey", cfg.ServiceAccount)
suite.True(cfg.Wait, "Wait should be aliased")
suite.True(cfg.Force, "Force should be aliased")
suite.Equal("Y29tZSB0byBteSBhcm1z", cfg.KubeToken, "KubeToken should be aliased")
suite.Equal("d2l0aCBpdHMgaGVhZA==", cfg.Certificate, "Certificate should be aliased")
}
func (suite *ConfigTestSuite) TestNewConfigSetsWriters() {