add envvar fallback to non prefix

This commit is contained in:
Ivan Pedrazas
2017-01-12 16:42:28 +00:00
parent 539cfab8cf
commit e6b79faab6
2 changed files with 42 additions and 3 deletions
+3 -3
View File
@@ -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)
}
+39
View File
@@ -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")
}
}