Skip to content

Commit

Permalink
Allow k8s to encode the secret (#24)
Browse files Browse the repository at this point in the history
* Allow k8s to encode the secret

* Fix test case

* Comment on the removal of explicitly encoding the string
  • Loading branch information
nextrevision authored and cllunsford committed Sep 28, 2016
1 parent b15eb02 commit 069667c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions vars.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/base64"
"fmt"
"io/ioutil"
"path"
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions vars_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/base64"
"reflect"
"testing"

Expand Down Expand Up @@ -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"),
},
}

Expand Down

0 comments on commit 069667c

Please sign in to comment.