Emit warnings about deprecated settings [#10]
These aren't an error case--the plugin will work just fine--but users should be aware they (the settings) aren't being respected.
This commit is contained in:
parent
353bd76f8f
commit
7cd46bb8b1
|
@ -59,7 +59,7 @@ steps:
|
||||||
drone-helm3 is largely backwards-compatible with drone-helm. There are some known differences:
|
drone-helm3 is largely backwards-compatible with drone-helm. There are some known differences:
|
||||||
|
|
||||||
* `prefix` must be supplied via the `settings` block, not `environment`.
|
* `prefix` must be supplied via the `settings` block, not `environment`.
|
||||||
* 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
|
* `purge` -- this is the default behavior in Helm 3
|
||||||
* `recreate_pods`
|
* `recreate_pods`
|
||||||
* `tiller_ns`
|
* `tiller_ns`
|
||||||
|
|
|
@ -4,10 +4,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/kelseyhightower/envconfig"
|
"github.com/kelseyhightower/envconfig"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"regexp"
|
"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
|
// 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
|
// config. Configuration in drone's `settings` block arrives as uppercase env vars matching the
|
||||||
|
@ -73,6 +78,8 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
|
||||||
cfg.logDebug()
|
cfg.logDebug()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.deprecationWarn()
|
||||||
|
|
||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,3 +89,13 @@ func (cfg Config) logDebug() {
|
||||||
}
|
}
|
||||||
fmt.Fprintf(cfg.Stderr, "Generated config: %+v\n", cfg)
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package helm
|
package helm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -123,6 +124,24 @@ func (suite *ConfigTestSuite) TestNewConfigSetsWriters() {
|
||||||
suite.Equal(stderr, cfg.Stderr)
|
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() {
|
func (suite *ConfigTestSuite) TestLogDebug() {
|
||||||
suite.setenv("DEBUG", "true")
|
suite.setenv("DEBUG", "true")
|
||||||
suite.setenv("HELM_COMMAND", "upgrade")
|
suite.setenv("HELM_COMMAND", "upgrade")
|
||||||
|
|
Loading…
Reference in a new issue