Merge pull request #51 from pelotech/deprecation-warnings
Emit warnings about deprecated settings
This commit is contained in:
commit
69a15a8d48
|
@ -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/).
|
* 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.
|
* 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
|
* `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
|
||||||
|
@ -64,6 +69,8 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
|
||||||
cfg.logDebug()
|
cfg.logDebug()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.deprecationWarn()
|
||||||
|
|
||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,3 +80,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"
|
||||||
|
@ -79,6 +80,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