Skip to content

Commit

Permalink
Fix kubectl create secret/configmap to allow = values
Browse files Browse the repository at this point in the history
  • Loading branch information
derekwaynecarr committed May 4, 2016
1 parent c0bcc04 commit 25ed62c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
15 changes: 15 additions & 0 deletions pkg/kubectl/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ func TestConfigMapGenerate(t *testing.T) {
},
expectErr: true,
},
{
params: map[string]interface{}{
"name": "foo",
"from-literal": []string{"key1==value1"},
},
expected: &api.ConfigMap{
ObjectMeta: api.ObjectMeta{
Name: "foo",
},
Data: map[string]string{
"key1": "=value1",
},
},
expectErr: false,
},
}
generator := ConfigMapGeneratorV1{}
for _, test := range tests {
Expand Down
7 changes: 6 additions & 1 deletion pkg/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ func parseFileSource(source string) (keyName, filePath string, err error) {

// parseLiteralSource parses the source key=val pair
func parseLiteralSource(source string) (keyName, value string, err error) {
items := strings.Split(source, "=")
// leading equal is invalid
if strings.Index(source, "=") == 0 {
return "", "", fmt.Errorf("invalid literal source %v, expected key=value", source)
}
// split after the first equal (so values can have the = character)
items := strings.SplitN(source, "=", 2)
if len(items) != 2 {
return "", "", fmt.Errorf("invalid literal source %v, expected key=value", source)
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/kubectl/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,23 @@ func TestParseLiteralSource(t *testing.T) {
{
name: "err 1",
input: "key==value",
err: true,
key: "key",
value: "=value",
err: false,
},
{
name: "err 2",
input: "key=value=",
err: true,
key: "key",
value: "value=",
err: false,
},
{
name: "err 3",
input: "key2=value==",
err: true,
key: "key2",
value: "value==",
err: false,
},
{
name: "err 4",
Expand Down
15 changes: 15 additions & 0 deletions pkg/kubectl/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ func TestSecretGenerate(t *testing.T) {
},
expectErr: true,
},
{
params: map[string]interface{}{
"name": "foo",
"from-literal": []string{"key1==value1"},
},
expected: &api.Secret{
ObjectMeta: api.ObjectMeta{
Name: "foo",
},
Data: map[string][]byte{
"key1": []byte("=value1"),
},
},
expectErr: false,
},
}
generator := SecretGeneratorV1{}
for _, test := range tests {
Expand Down

0 comments on commit 25ed62c

Please sign in to comment.