From 66c8f60f02d9b41766cabd1d207af8cf39a6523b Mon Sep 17 00:00:00 2001 From: Sami Hiltunen Date: Thu, 20 Oct 2016 11:43:51 +0200 Subject: [PATCH] kubectl: commas in --from-literal on secret creation * Fixes an issue where commas were not accepted in --from-literal arguments when creating secrets. (closes #35185) --- pkg/kubectl/cmd/create_secret.go | 4 ++-- pkg/kubectl/cmd/create_secret_test.go | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/kubectl/cmd/create_secret.go b/pkg/kubectl/cmd/create_secret.go index 8495f4db79b..d96058ff0ed 100644 --- a/pkg/kubectl/cmd/create_secret.go +++ b/pkg/kubectl/cmd/create_secret.go @@ -85,7 +85,7 @@ func NewCmdCreateSecretGeneric(f cmdutil.Factory, cmdOut io.Writer) *cobra.Comma cmdutil.AddPrinterFlags(cmd) cmdutil.AddGeneratorFlags(cmd, cmdutil.SecretV1GeneratorName) cmd.Flags().StringSlice("from-file", []string{}, "Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key.") - cmd.Flags().StringSlice("from-literal", []string{}, "Specify a key and literal value to insert in secret (i.e. mykey=somevalue)") + cmd.Flags().StringArray("from-literal", []string{}, "Specify a key and literal value to insert in secret (i.e. mykey=somevalue)") cmd.Flags().String("type", "", "The type of secret to create") return cmd } @@ -103,7 +103,7 @@ func CreateSecretGeneric(f cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command Name: name, Type: cmdutil.GetFlagString(cmd, "type"), FileSources: cmdutil.GetFlagStringSlice(cmd, "from-file"), - LiteralSources: cmdutil.GetFlagStringSlice(cmd, "from-literal"), + LiteralSources: cmdutil.GetFlagStringArray(cmd, "from-literal"), } default: return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName)) diff --git a/pkg/kubectl/cmd/create_secret_test.go b/pkg/kubectl/cmd/create_secret_test.go index f698e811400..fe26bea9ea8 100644 --- a/pkg/kubectl/cmd/create_secret_test.go +++ b/pkg/kubectl/cmd/create_secret_test.go @@ -27,7 +27,12 @@ import ( ) func TestCreateSecretGeneric(t *testing.T) { - secretObject := &api.Secret{} + secretObject := &api.Secret{ + Data: map[string][]byte{ + "password": []byte("includes,comma"), + "username": []byte("test_user"), + }, + } secretObject.Name = "my-secret" f, tf, codec, ns := cmdtesting.NewAPIFactory() tf.Printer = &testPrinter{} @@ -47,6 +52,8 @@ func TestCreateSecretGeneric(t *testing.T) { buf := bytes.NewBuffer([]byte{}) cmd := NewCmdCreateSecretGeneric(f, buf) cmd.Flags().Set("output", "name") + cmd.Flags().Set("from-literal", "password=includes,comma") + cmd.Flags().Set("from-literal", "username=test_user") cmd.Run(cmd, []string{secretObject.Name}) expectedOutput := "secret/" + secretObject.Name + "\n" if buf.String() != expectedOutput {