-
Notifications
You must be signed in to change notification settings - Fork 382
Svcat bind params now supports --params-json #1889
Changes from all commits
84f52a9
94c89b0
4b7bc89
60c9d5f
8cb531d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ type bindCmd struct { | |
bindingName string | ||
secretName string | ||
rawParams []string | ||
params map[string]string | ||
jsonParams string | ||
params interface{} | ||
rawSecrets []string | ||
secrets map[string]string | ||
} | ||
|
@@ -45,6 +46,16 @@ func NewBindCmd(cxt *command.Context) *cobra.Command { | |
Example: ` | ||
svcat bind wordpress | ||
svcat bind wordpress-mysql-instance --name wordpress-mysql-binding --secret-name wordpress-mysql-secret | ||
svcat bind wordpress-instance --params type=admin | ||
svcat bind wordpress-instance --params-json '{ | ||
"type": "admin", | ||
"teams": [ | ||
"news", | ||
"weather", | ||
"sports" | ||
] | ||
} | ||
' | ||
`, | ||
PreRunE: command.PreRunE(bindCmd), | ||
RunE: command.RunE(bindCmd), | ||
|
@@ -65,10 +76,11 @@ func NewBindCmd(cxt *command.Context) *cobra.Command { | |
"The name of the secret. Defaults to the name of the instance.", | ||
) | ||
cmd.Flags().StringSliceVarP(&bindCmd.rawParams, "param", "p", nil, | ||
"Additional parameter to use when binding the instance, format: NAME=VALUE") | ||
"Additional parameter to use when binding the instance, format: NAME=VALUE. Cannot be combined with --params-json") | ||
cmd.Flags().StringSliceVarP(&bindCmd.rawSecrets, "secret", "s", nil, | ||
"Additional parameter, whose value is stored in a secret, to use when binding the instance, format: SECRET[KEY]") | ||
|
||
cmd.Flags().StringVar(&bindCmd.jsonParams, "params-json", "", | ||
"Additional parameters to use when binding the instance, provided as a JSON object. Cannot be combined with --param") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have a message (fine to be in a follow up) warning people not to use this for secret information. |
||
return cmd | ||
} | ||
|
||
|
@@ -79,9 +91,21 @@ func (c *bindCmd) Validate(args []string) error { | |
c.instanceName = args[0] | ||
|
||
var err error | ||
c.params, err = parameters.ParseVariableAssignments(c.rawParams) | ||
if err != nil { | ||
return fmt.Errorf("invalid --param value (%s)", err) | ||
|
||
if c.jsonParams != "" && len(c.rawParams) > 0 { | ||
return fmt.Errorf("--params-json cannot be used with --param") | ||
} | ||
|
||
if c.jsonParams != "" { | ||
c.params, err = parameters.ParseVariableJSON(c.jsonParams) | ||
if err != nil { | ||
return fmt.Errorf("invalid --params-json value (%s)", err) | ||
} | ||
} else { | ||
c.params, err = parameters.ParseVariableAssignments(c.rawParams) | ||
if err != nil { | ||
return fmt.Errorf("invalid --param value (%s)", err) | ||
} | ||
} | ||
|
||
c.secrets, err = parameters.ParseKeyMaps(c.rawSecrets) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ func (c *provisonCmd) Validate(args []string) error { | |
if c.jsonParams != "" { | ||
c.params, err = parameters.ParseVariableJSON(c.jsonParams) | ||
if err != nil { | ||
return fmt.Errorf("invalid --params value (%s)", err) | ||
return fmt.Errorf("invalid --params-json value (%s)", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! |
||
} | ||
} else { | ||
c.params, err = parameters.ParseVariableAssignments(c.rawParams) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ func (sdk *SDK) RetrieveBindingsByInstance(instance *v1beta1.ServiceInstance, | |
|
||
// Bind an instance to a secret. | ||
func (sdk *SDK) Bind(namespace, bindingName, instanceName, secretName string, | ||
params map[string]string, secrets map[string]string) (*v1beta1.ServiceBinding, error) { | ||
params interface{}, secrets map[string]string) (*v1beta1.ServiceBinding, error) { | ||
|
||
// Manually defaulting the name of the binding | ||
// I'm not doing the same for the secret since the API handles defaulting that value. | ||
|
@@ -137,7 +137,7 @@ func (sdk *SDK) Unbind(ns, instanceName string) ([]v1beta1.ServiceBinding, error | |
} | ||
|
||
//Range over the deleted bindings to build a slice to return | ||
deleted := []v1beta1.ServiceBinding{} | ||
deleted := []v1beta1.ServiceBinding(nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel silly asking but what does this change do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
TBH: goland tells me using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I bow to the superior skills of Goland. Good to know what that means, thanks! 👍 |
||
for b := range deletedBindings { | ||
deleted = append(deleted, b) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it.
I would like a version of this that was
--secret-params-json
and let you put a json blob into a secret that was referenced.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the result of that command create a new secret and then use the secret just like we currently do with
--secret-name NAME
?We would have to have some way to clean that secret up after the operation has finished. I think this sounds like a good idea and I am guessing most users would not understand that sending params via svcat exposes those to the other users of k8s.
update: Oh I needed to read better. We would be updating the contents of the secret with the blob, and we pass in the name of the secret.
Yeah! nice. made and issue: #1898
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understand, the difference between
--secret
and this new flag would be that it would handle making the secret for you and setting the secret paramsfrom on the instance for you?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carolynvs I misunderstood the suggestion at first. I think @pmorie was suggesting the simpler case of supporting exactly what the current
--secret
does except provide the secret pairs as a json blob provided by--secret-json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! @pmorie can you weigh in when you get a chance? 😀