diff --git a/README.md b/README.md index ec34126..d5d7fde 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,8 @@ drone-helm3 is largely backwards-compatible with drone-helm. There are some know * You'll need to migrate the deployments in the cluster [helm-v2-to-helm-v3](https://helm.sh/blog/migrate-from-helm-v2-to-helm-v3/). * The `prefix` setting is no longer supported. If you were relying on the `prefix` setting with `secrets: [...]`, you'll need to switch to the `from_secret` syntax. -* Several settings no longer have any effect: +* Several settings no longer have any effect. The plugin will produce warnings if any of these are present: + * `purge` -- this is the default behavior in Helm 3 * `recreate_pods` * `tiller_ns` diff --git a/internal/helm/config.go b/internal/helm/config.go index 3406c1f..2365ce2 100644 --- a/internal/helm/config.go +++ b/internal/helm/config.go @@ -4,10 +4,15 @@ import ( "fmt" "github.com/kelseyhightower/envconfig" "io" + "os" "regexp" + "strings" ) -var justNumbers = regexp.MustCompile(`^\d+$`) +var ( + justNumbers = regexp.MustCompile(`^\d+$`) + deprecatedVars = []string{"PURGE", "RECREATE_PODS", "TILLER_NS", "UPGRADE", "CANARY_IMAGE", "CLIENT_ONLY", "STABLE_REPO_URL"} +) // The Config struct captures the `settings` and `environment` blocks in the application's drone // config. Configuration in drone's `settings` block arrives as uppercase env vars matching the @@ -64,6 +69,8 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) { cfg.logDebug() } + cfg.deprecationWarn() + return &cfg, nil } @@ -73,3 +80,13 @@ func (cfg Config) logDebug() { } fmt.Fprintf(cfg.Stderr, "Generated config: %+v\n", cfg) } + +func (cfg *Config) deprecationWarn() { + for _, varname := range deprecatedVars { + _, barePresent := os.LookupEnv(varname) + _, prefixedPresent := os.LookupEnv("PLUGIN_" + varname) + if barePresent || prefixedPresent { + fmt.Fprintf(cfg.Stderr, "Warning: ignoring deprecated '%s' setting\n", strings.ToLower(varname)) + } + } +} diff --git a/internal/helm/config_test.go b/internal/helm/config_test.go index 40ddfd6..6cad789 100644 --- a/internal/helm/config_test.go +++ b/internal/helm/config_test.go @@ -1,6 +1,7 @@ package helm import ( + "fmt" "github.com/stretchr/testify/suite" "os" "strings" @@ -79,6 +80,24 @@ func (suite *ConfigTestSuite) TestNewConfigSetsWriters() { suite.Equal(stderr, cfg.Stderr) } +func (suite *ConfigTestSuite) TestDeprecatedSettingWarnings() { + for _, varname := range deprecatedVars { + suite.setenv(varname, "deprecoat") // environment-block entries should cause warnings + } + + suite.unsetenv("PURGE") + suite.setenv("PLUGIN_PURGE", "true") // settings-block entries should cause warnings + suite.setenv("UPGRADE", "") // entries should cause warnings even when set to empty string + + stderr := &strings.Builder{} + _, err := NewConfig(&strings.Builder{}, stderr) + suite.NoError(err) + + for _, varname := range deprecatedVars { + suite.Contains(stderr.String(), fmt.Sprintf("Warning: ignoring deprecated '%s' setting\n", strings.ToLower(varname))) + } +} + func (suite *ConfigTestSuite) TestLogDebug() { suite.setenv("DEBUG", "true") suite.setenv("HELM_COMMAND", "upgrade")