Merge pull request #60 from jmccann/skip-secrets

allow specifying server, token, values and serviceaccount outside env
This commit is contained in:
Ivan Pedrazas
2018-05-04 11:15:54 +02:00
committed by GitHub
2 changed files with 46 additions and 5 deletions
+10 -4
View File
@@ -286,11 +286,17 @@ func runCommand(params []string) error {
func resolveSecrets(p *Plugin) {
p.Config.Values = resolveEnvVar(p.Config.Values, p.Config.Prefix, p.Config.Debug)
p.Config.APIServer = resolveEnvVar("${API_SERVER}", p.Config.Prefix, p.Config.Debug)
p.Config.Token = resolveEnvVar("${KUBERNETES_TOKEN}", p.Config.Prefix, p.Config.Debug)
p.Config.ServiceAccount = resolveEnvVar("${SERVICE_ACCOUNT}", p.Config.Prefix, p.Config.Debug)
if p.Config.APIServer == "" {
p.Config.APIServer = resolveEnvVar("${API_SERVER}", p.Config.Prefix, p.Config.Debug)
}
if p.Config.Token == "" {
p.Config.Token = resolveEnvVar("${KUBERNETES_TOKEN}", p.Config.Prefix, p.Config.Debug)
}
if p.Config.ServiceAccount == "" {
p.Config.ServiceAccount = "helm"
p.Config.ServiceAccount = resolveEnvVar("${SERVICE_ACCOUNT}", p.Config.Prefix, p.Config.Debug)
if p.Config.ServiceAccount == "" {
p.Config.ServiceAccount = "helm"
}
}
}
+36 -1
View File
@@ -151,6 +151,7 @@ func TestGetHelmDeleteCommandOverried(t *testing.T) {
func TestResolveSecrets(t *testing.T) {
// Test resolving secrets from env
testEnvs := []struct {
prefix string
tag string
@@ -208,10 +209,44 @@ func TestResolveSecrets(t *testing.T) {
}
// clean up
for envKey, _ := range envMap {
for envKey := range envMap {
os.Unsetenv(fmt.Sprintf("%s_%s", env.prefix, envKey))
}
}
// Test resolving provided values
testInput := []struct {
server string
values string
token string
account string
}{
{server: "http://apiserver2", token: "123456", account: "helm2", values: "aval=test"},
}
for _, input := range testInput {
plugin := &Plugin{
Config: Config{
APIServer: input.server,
ServiceAccount: input.account,
Token: input.token,
Values: input.values,
},
}
resolveSecrets(plugin)
if plugin.Config.APIServer != input.server {
t.Errorf("failed to keep APIServer '%s' got '%s'", input.server, plugin.Config.APIServer)
}
if plugin.Config.ServiceAccount != input.account {
t.Errorf("failed to keep ServiceAccount '%s' got '%s'", input.account, plugin.Config.ServiceAccount)
}
if plugin.Config.Token != input.token {
t.Errorf("failed to keep Token '%s' got '%s'", input.token, plugin.Config.Token)
}
if plugin.Config.Values != input.values {
t.Errorf("failed to keep Values '%s' got '%s'", input.values, plugin.Config.Values)
}
}
}
func TestDetHelmRepoAdd(t *testing.T) {