Merge pull request #24989 from derekwaynecarr/fix_secret_cmd

Fix kubectl create secret/configmap to allow = values
This commit is contained in:
Robert Bailey 2016-05-06 15:18:50 -07:00
commit 0db3ca4b50
4 changed files with 45 additions and 4 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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",

View File

@ -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 {