From 069667c7d6c90a15930c52ae19d9c2cdfed59425 Mon Sep 17 00:00:00 2001 From: John Patterson Date: Wed, 28 Sep 2016 09:54:58 -0500 Subject: [PATCH] Allow k8s to encode the secret (#24) * Allow k8s to encode the secret * Fix test case * Comment on the removal of explicitly encoding the string --- README.md | 2 -- vars.go | 7 ++++--- vars_test.go | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0d8a70d..0de8e96 100644 --- a/README.md +++ b/README.md @@ -233,8 +233,6 @@ kind: Deployment ... snip ... ``` -NOTE: Environment variables injected as from a secret must be decoded as base64 before use. - ### Plaintext, ConfigMaps, and Secrets Combining the examples above into one command, you would get the following output: diff --git a/vars.go b/vars.go index 6fcf5c9..4e4f327 100644 --- a/vars.go +++ b/vars.go @@ -1,7 +1,6 @@ package main import ( - "encoding/base64" "fmt" "io/ioutil" "path" @@ -164,6 +163,8 @@ func (vars Vars) toConfigMap(name string, namespace string, convert bool) ([]v1. return envVars, configMap, nil } +// toSecret converts vars to a Secret resource and creates the proper EnvVar +// ValuesFrom sources to be passed to the container func (vars Vars) toSecret(name string, namespace string, convert bool) ([]v1.EnvVar, *v1.Secret, error) { envVars := []v1.EnvVar{} data := make(map[string][]byte) @@ -174,8 +175,8 @@ func (vars Vars) toSecret(name string, namespace string, convert bool) ([]v1.Env return envVars, &v1.Secret{}, err } - encodedValue := base64.StdEncoding.EncodeToString([]byte(v.Value)) - data[key] = []byte(encodedValue) + // the k8s lib will handle the base64 encoding for us + data[key] = []byte(v.Value) envVars = append(envVars, v1.EnvVar{ Name: v.Key, diff --git a/vars_test.go b/vars_test.go index d4d0e22..e1d69a0 100644 --- a/vars_test.go +++ b/vars_test.go @@ -1,7 +1,6 @@ package main import ( - "encoding/base64" "reflect" "testing" @@ -218,8 +217,8 @@ func TestToSecret(t *testing.T) { Namespace: "bar", }, Data: map[string][]byte{ - "KVKey1": []byte(base64.StdEncoding.EncodeToString([]byte("KVValue1"))), - "kvkey2": []byte(base64.StdEncoding.EncodeToString([]byte("kvvalue2"))), + "KVKey1": []byte("KVValue1"), + "kvkey2": []byte("kvvalue2"), }, }