mirror of
https://github.com/ipedrazas/drone-helm.git
synced 2026-07-06 16:02:36 +08:00
add envvar fallback to non prefix
This commit is contained in:
@@ -168,10 +168,10 @@ func replaceEnvvars(envvars [][]string, prefix string, s string) string {
|
||||
for _, envvar := range envvars {
|
||||
envvarName := envvar[0]
|
||||
envvarKey := envvar[2]
|
||||
if prefix != "" {
|
||||
envvarKey = prefix + "_" + envvarKey
|
||||
envval := os.Getenv(prefix + "_" + envvarKey)
|
||||
if envval == "" {
|
||||
envval = os.Getenv(envvarKey)
|
||||
}
|
||||
envval := os.Getenv(envvarKey)
|
||||
if strings.Contains(s, envvarName) {
|
||||
s = strings.Replace(s, envvarName, envval, -1)
|
||||
}
|
||||
|
||||
@@ -167,3 +167,42 @@ func TestDetHelmInit(t *testing.T) {
|
||||
t.Error("Tiller not installed in proper namespace")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveSecretsFallback(t *testing.T) {
|
||||
tag := "v0.1.1"
|
||||
api := "http://apiserver"
|
||||
os.Setenv("MY_TAG", tag)
|
||||
os.Setenv("MY_API_SERVER", api)
|
||||
os.Setenv("MY_TOKEN", "12345")
|
||||
os.Setenv("NOTTOKEN", "99999")
|
||||
|
||||
plugin := &Plugin{
|
||||
Config: Config{
|
||||
HelmCommand: nil,
|
||||
Namespace: "default",
|
||||
SkipTLSVerify: true,
|
||||
Debug: true,
|
||||
DryRun: true,
|
||||
Chart: "./chart/test",
|
||||
Release: "test-release",
|
||||
Prefix: "MY",
|
||||
Values: "image.tag=$TAG,api=${API_SERVER},nottoken=${NOTTOKEN},nameOverride=my-over-app,second.tag=${TAG}",
|
||||
},
|
||||
}
|
||||
|
||||
resolveSecrets(plugin)
|
||||
// test that the subsitution works
|
||||
if !strings.Contains(plugin.Config.Values, tag) {
|
||||
t.Errorf("env var ${TAG} not resolved %s", tag)
|
||||
}
|
||||
if strings.Contains(plugin.Config.Values, "${TAG}") {
|
||||
t.Errorf("env var ${TAG} not resolved %s", tag)
|
||||
}
|
||||
|
||||
if plugin.Config.APIServer != api {
|
||||
t.Errorf("env var ${API_SERVER} not resolved %s", api)
|
||||
}
|
||||
if !strings.Contains(plugin.Config.Values, "99999") {
|
||||
t.Errorf("envar ${NOTTOKEN} has not been resolved to 99999, not using prefix")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user