Default to the canonical setting names [#66]
The goal with these changes was to give users a clearer, more readable interface, so we should present that interface up front and only document the aliases as a backward-compatibility option. I've renamed the envconfig tags to reflect the switch, but I left the actual field names the same. I think they're sufficiently meaningful inside the code, and leaving them unchanged avoids making a bunch of churn in the rest of the code.
This commit is contained in:
@@ -20,29 +20,29 @@ var (
|
||||
// not have the `PLUGIN_` prefix.
|
||||
type Config struct {
|
||||
// Configuration for drone-helm itself
|
||||
Command string `envconfig:"HELM_COMMAND"` // Helm command to run
|
||||
Command string `envconfig:"mode"` // Helm command to run
|
||||
DroneEvent string `envconfig:"DRONE_BUILD_EVENT"` // Drone event that invoked this plugin.
|
||||
UpdateDependencies bool `split_words:"true"` // Call `helm dependency update` before the main command
|
||||
AddRepos []string `envconfig:"HELM_REPOS"` // Call `helm repo add` before the main command
|
||||
AddRepos []string `split_words:"true"` // Call `helm repo add` before the main command
|
||||
Debug bool `` // Generate debug output and pass --debug to all helm commands
|
||||
Values string `` // Argument to pass to --set in applicable helm commands
|
||||
StringValues string `split_words:"true"` // Argument to pass to --set-string in applicable helm commands
|
||||
ValuesFiles []string `split_words:"true"` // Arguments to pass to --values in applicable helm commands
|
||||
Namespace string `` // Kubernetes namespace for all helm commands
|
||||
KubeToken string `envconfig:"KUBERNETES_TOKEN"` // Kubernetes authentication token to put in .kube/config
|
||||
KubeToken string `split_words:"true"` // Kubernetes authentication token to put in .kube/config
|
||||
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 `split_words:"true"` // Account to use for connecting to the Kubernetes cluster
|
||||
Certificate string `envconfig:"kube_certificate"` // The Kubernetes cluster CA's self-signed certificate (must be base64-encoded)
|
||||
APIServer string `envconfig:"kube_api_server"` // The Kubernetes cluster's API endpoint
|
||||
ServiceAccount string `envconfig:"kube_service_account"` // 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
|
||||
Wait bool `envconfig:"wait_for_upgrade"` // Pass --wait to applicable helm commands
|
||||
ReuseValues bool `split_words:"true"` // Pass --reuse-values to `helm upgrade`
|
||||
KeepHistory bool `split_words:"true"` // Pass --keep-history to `helm uninstall`
|
||||
Timeout string `` // Argument to pass to --timeout in applicable helm commands
|
||||
Chart string `` // Chart argument to use in applicable helm commands
|
||||
Release string `` // Release argument to use in applicable helm commands
|
||||
Force bool `` // Pass --force to applicable helm commands
|
||||
Force bool `envconfig:"force_upgrade"` // Pass --force to applicable helm commands
|
||||
AtomicUpgrade bool `split_words:"true"` // Pass --atomic to `helm upgrade`
|
||||
CleanupOnFail bool `envconfig:"CLEANUP_FAILED_UPGRADE"` // Pass --cleanup-on-fail to `helm upgrade`
|
||||
LintStrictly bool `split_words:"true"` // Pass --strict to `helm lint`
|
||||
@@ -114,12 +114,12 @@ func (cfg *Config) deprecationWarn() {
|
||||
}
|
||||
|
||||
type settingAliases struct {
|
||||
Command string `envconfig:"mode"`
|
||||
AddRepos []string `envconfig:"add_repos"`
|
||||
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"`
|
||||
Command string `envconfig:"helm_command"`
|
||||
AddRepos []string `envconfig:"helm_repos"`
|
||||
APIServer string `envconfig:"api_server"`
|
||||
ServiceAccount string `split_words:"true"`
|
||||
Wait bool ``
|
||||
Force bool ``
|
||||
KubeToken string `envconfig:"kubernetes_token"`
|
||||
Certificate string `envconfig:"kubernetes_certificate"`
|
||||
}
|
||||
|
||||
@@ -20,47 +20,47 @@ func TestConfigTestSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithPluginPrefix() {
|
||||
suite.unsetenv("HELM_COMMAND")
|
||||
suite.unsetenv("MODE")
|
||||
suite.unsetenv("UPDATE_DEPENDENCIES")
|
||||
suite.unsetenv("DEBUG")
|
||||
|
||||
suite.setenv("PLUGIN_HELM_COMMAND", "execute order 66")
|
||||
suite.setenv("PLUGIN_MODE", "iambic")
|
||||
suite.setenv("PLUGIN_UPDATE_DEPENDENCIES", "true")
|
||||
suite.setenv("PLUGIN_DEBUG", "true")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("execute order 66", cfg.Command)
|
||||
suite.Equal("iambic", cfg.Command)
|
||||
suite.True(cfg.UpdateDependencies)
|
||||
suite.True(cfg.Debug)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithNoPrefix() {
|
||||
suite.unsetenv("PLUGIN_HELM_COMMAND")
|
||||
suite.unsetenv("PLUGIN_MODE")
|
||||
suite.unsetenv("PLUGIN_UPDATE_DEPENDENCIES")
|
||||
suite.unsetenv("PLUGIN_DEBUG")
|
||||
|
||||
suite.setenv("HELM_COMMAND", "execute order 66")
|
||||
suite.setenv("MODE", "iambic")
|
||||
suite.setenv("UPDATE_DEPENDENCIES", "true")
|
||||
suite.setenv("DEBUG", "true")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("execute order 66", cfg.Command)
|
||||
suite.Equal("iambic", cfg.Command)
|
||||
suite.True(cfg.UpdateDependencies)
|
||||
suite.True(cfg.Debug)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithConflictingVariables() {
|
||||
suite.setenv("PLUGIN_HELM_COMMAND", "execute order 66")
|
||||
suite.setenv("HELM_COMMAND", "defend the jedi") // values from the `environment` block override those from `settings`
|
||||
suite.setenv("PLUGIN_MODE", "iambic")
|
||||
suite.setenv("MODE", "haiku") // values from the `environment` block override those from `settings`
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("defend the jedi", cfg.Command)
|
||||
suite.Equal("haiku", cfg.Command)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigInfersNumbersAreSeconds() {
|
||||
@@ -72,30 +72,30 @@ func (suite *ConfigTestSuite) TestNewConfigInfersNumbersAreSeconds() {
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithAliases() {
|
||||
for _, varname := range []string{
|
||||
"HELM_COMMAND",
|
||||
"HELM_REPOS",
|
||||
"API_SERVER",
|
||||
"SERVICE_ACCOUNT",
|
||||
"WAIT",
|
||||
"FORCE",
|
||||
"KUBERNETES_TOKEN",
|
||||
"KUBERNETES_CERTIFICATE",
|
||||
"MODE",
|
||||
"ADD_REPOS",
|
||||
"KUBE_API_SERVER",
|
||||
"KUBE_SERVICE_ACCOUNT",
|
||||
"WAIT_FOR_UPGRADE",
|
||||
"FORCE_UPGRADE",
|
||||
"KUBE_TOKEN",
|
||||
"KUBE_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_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==")
|
||||
suite.setenv("PLUGIN_HELM_COMMAND", "beware the jabberwock")
|
||||
suite.setenv("PLUGIN_HELM_REPOS", "chortle=http://calloo.callay/frabjous/day")
|
||||
suite.setenv("PLUGIN_API_SERVER", "http://tumtum.tree")
|
||||
suite.setenv("PLUGIN_SERVICE_ACCOUNT", "tulgey")
|
||||
suite.setenv("PLUGIN_WAIT", "true")
|
||||
suite.setenv("PLUGIN_FORCE", "true")
|
||||
suite.setenv("PLUGIN_KUBERNETES_TOKEN", "Y29tZSB0byBteSBhcm1z")
|
||||
suite.setenv("PLUGIN_KUBERNETES_CERTIFICATE", "d2l0aCBpdHMgaGVhZA==")
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal("iambic", cfg.Command)
|
||||
suite.Equal("beware the jabberwock", cfg.Command)
|
||||
suite.Equal([]string{"chortle=http://calloo.callay/frabjous/day"}, cfg.AddRepos)
|
||||
suite.Equal("http://tumtum.tree", cfg.APIServer)
|
||||
suite.Equal("tulgey", cfg.ServiceAccount)
|
||||
@@ -106,9 +106,9 @@ func (suite *ConfigTestSuite) TestNewConfigWithAliases() {
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigWithAliasConflicts() {
|
||||
suite.unsetenv("FORCE")
|
||||
suite.setenv("PLUGIN_FORCE_UPGRADE", "true")
|
||||
suite.setenv("PLUGIN_FORCE", "false") // should override even when set to the zero value
|
||||
suite.unsetenv("FORCE_UPGRADE")
|
||||
suite.setenv("PLUGIN_FORCE", "true")
|
||||
suite.setenv("PLUGIN_FORCE_UPGRADE", "false") // should override even when set to the zero value
|
||||
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.NoError(err)
|
||||
@@ -145,7 +145,7 @@ func (suite *ConfigTestSuite) TestDeprecatedSettingWarnings() {
|
||||
|
||||
func (suite *ConfigTestSuite) TestLogDebug() {
|
||||
suite.setenv("DEBUG", "true")
|
||||
suite.setenv("HELM_COMMAND", "upgrade")
|
||||
suite.setenv("MODE", "upgrade")
|
||||
|
||||
stderr := strings.Builder{}
|
||||
stdout := strings.Builder{}
|
||||
|
||||
Reference in New Issue
Block a user