Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Add flags to svcat register broker command #2208

Merged

Conversation

jberkhahn
Copy link
Contributor

@jberkhahn jberkhahn commented Jul 17, 2018

#1807

Also contains refactoring of register to change mandatory flags into positional args.

Also adds an options struct to pkg/svcat for containing the bajillion different flag options. This also makes the interface around Register() much more stable.

I'm centering validation in the cmd layer's Validate() method (from cobra). So pkg/svcat's Register() method will do strange things if you ask it to.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 17, 2018
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 17, 2018
@jberkhahn jberkhahn added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 17, 2018
@MHBauer
Copy link
Contributor

MHBauer commented Jul 17, 2018

if you put WIP into the title of the PR it automatically applies the label.

@MHBauer
Copy link
Contributor

MHBauer commented Jul 17, 2018

I dunno how to read regexes, but here https://github.com/kubernetes/test-infra/blob/master/prow/plugins/wip/wip-label.go#L41

@jberkhahn jberkhahn force-pushed the svcat_register_flags branch 2 times, most recently from d551332 to d02d379 Compare July 17, 2018 23:24
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 17, 2018
@jberkhahn jberkhahn added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 20, 2018
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 24, 2018
@jberkhahn jberkhahn removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 24, 2018
@jberkhahn jberkhahn requested a review from carolynvs July 24, 2018 21:43
@jberkhahn jberkhahn force-pushed the svcat_register_flags branch 2 times, most recently from f1b9e85 to bde82bc Compare July 24, 2018 22:15
Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good! 👍

FYI, I didn't review the tests yet, I'll look at those once the desired behavior is clarified.

PlanRestrictions []string
SkipTLS bool
RelistBehavior string
RelistDuration time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always confused by what a create should look like with a manual relistduration. Should we pass a null duration or does the api server just ignore whatever is sent for the duration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sends a time.Duration of 0, which the apiserver drops on the floor. It never gets set in the spec at all.

}
cmd := &cobra.Command{
Use: "register NAME --url URL",
Use: "register NAME URL",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol I see what you did there. 😂 My vote is still for keeping --url.

cmd.Flags().StringVar(&registerCmd.URL, "url", "",
"The broker URL (Required)")
cmd.MarkFlagRequired("url")
cmd.Flags().StringVar(&registerCmd.BasicSecret, "basic-secret", "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know how the secrets work when we are making a ClusterServiceBroker vs a ServiceBroker. For a namespaced broker, I assume that the secret is in the same namespace. For a cluster-scoped broker though, do they have to provide a namespace? Or is it just embedded in the format, e.g. "namespace/secret-name"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it tags the secret as being in whatever namespace the command was executed in. This might be a problem when we want to change the command to create namespaced broker.

cmd.Flags().StringVar(&registerCmd.CAFile, "ca", "",
"A file containing the CA certificate to connect to the broker")
cmd.Flags().StringSliceVar(&registerCmd.ClassRestrictions, "class-restrictions", []string{},
"A whitelist of Classes to allow from the broker")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use blacklist/whitelist and stick with the terms that are used in the documentation:

https://svc-cat.io/docs/catalog-restrictions/

I recommend "A list of restrictions to apply to the classes allowed from the broker" or something like that.

cmd.Flags().StringSliceVar(&registerCmd.PlanRestrictions, "plan-restrictions", []string{},
"A whitelist of Plans to allow from the broker")
cmd.Flags().StringVar(&registerCmd.RelistBehavior, "relist-behavior", "",
"Behavior for relisting the broker's catalogue. Manual/Duration")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use the US spelling "catalog" everywhere else, so let's rename "catalogue" to "catalog" for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd.Flags().StringVar(&registerCmd.RelistBehavior, "relist-behavior", "",
"Behavior for relisting the broker's catalogue. Manual/Duration")
cmd.Flags().DurationVar(&registerCmd.RelistDuration, "relist-duration", 0*time.Second,
"Interval to refetch broker catalog when relist-behavior is set to duration, specified in human readable format: 30s, 1m, 1h")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implies that we only use relist-duration when the behavior is manual, is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, what? Its the interval to (do thing) when relist behavior is set to duration. That means we only use it when the behavior is duration.

right?

if c.RelistBehavior != "" {
c.RelistBehavior = strings.ToLower(c.RelistBehavior)
if c.RelistBehavior != "duration" && c.RelistBehavior != "manual" {
return fmt.Errorf("relist-behavior must be duration/manual")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use "invalid --relist-duration value, allowed values are: duration, manual" to match our other error messages.

return fmt.Errorf("relist-behavior must be duration/manual")
}
}
if c.RelistDuration != 0*time.Second && c.RelistBehavior != "duration" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that the api server would accept? I am wondering if we are applying validations on the cli to values that the server would allow. Can you check please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api server drops the relist duration on the ground. I guess we can remove this.

return nil
}

// Run runs the command
// Run calls out to the pkg lib to create the broker and displays the output
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's not put the call pattern into the comment. How about // Run creates the broker and then displays the broker details

BearerSecret: c.BearerSecret,
CAFile: c.CAFile,
ClassRestrictions: c.ClassRestrictions,
Namespace: c.Context.App.CurrentNamespace,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not directly use the current namespace, because that doesn't properly take into account all of the necessary logic. The Namespaced struct handles defaulting this appropriately, and the final namespace can be found in c.Namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does that interact with throwing the global kubectl namespace flag when running in plugin mode?

@jberkhahn jberkhahn force-pushed the svcat_register_flags branch 5 times, most recently from b782122 to e91bf56 Compare July 26, 2018 20:50
@jberkhahn
Copy link
Contributor Author

redid the namespace stuff using namespaced

}
cmd := &cobra.Command{
Use: "register NAME --url URL",
Use: "register NAME URL",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this back to --url.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General consensus at the face to face and in the meeting before that was to move to positional arguments and get rid of mandatory flags. Do you want to bring this up again next week in the meeting to discuss?

return fmt.Errorf("invalid --relist-duration value, allowed values are: duration, manual")
}
}
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this dead code / comment.

@@ -0,0 +1 @@
foo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best CA cert ever ⭐️

}
cmd := &cobra.Command{
Use: "register NAME --url URL",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we change this? I'm not sure I really like the positional arguments like this. The cf CLI does this, but I think kubernetes gets more into -- args vs positional things and I think we should stick with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we discussed this at the face-to-face. We decided to switch to positional args as mandatory flags goes against unix command line convention.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this isn't the hill I want to die on 😝, I honestly do not remember that being officially decided at the F2F as you are recalling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jberkhahn I apologize for this being so weird. I trust that we did decide that and I just forgot the details. Let's go with what you have here and I now crown you master and commander of the CLI so that we don't have to rely on my poor memory anymore!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahhahah I was thinking of a 👑 , jeremy immediately went to that ⛵️ movie and I think that's a beefeater? best title ever! 🙌

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have been on one of those bathroom breaks - - I too don't recall the position vs named arg discussion/decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No? We also discussed this in the weekly meeting the week before the f2f and had the same consensus. We can bring it up again at the meeting next week if you prefer.

@jeremyrickard
Copy link
Contributor

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 9, 2018
@jeremyrickard
Copy link
Contributor

@jberkhahn @jboyd01 @carolynvs I put this on hold for now, I feel like we should chat about it Monday since there seems to be some confusion about args. Let's just revisit the topic and then we can come back to this!

@jberkhahn jberkhahn dismissed jeremyrickard’s stale review August 13, 2018 20:56

removed the changes in question

@jberkhahn jberkhahn removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 13, 2018
Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2018
@k8s-ci-robot k8s-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2018
- add options object to pkg/svcat
- change svcat register --url flag to positional argument
@carolynvs
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 14, 2018
@jeremyrickard
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jeremyrickard

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 14, 2018
@@ -48,27 +68,73 @@ func NewRegisterCmd(cxt *command.Context) *cobra.Command {
cmd.Flags().StringVar(&registerCmd.URL, "url", "",
"The broker URL (Required)")
cmd.MarkFlagRequired("url")
cmd.Flags().StringVar(&registerCmd.BasicSecret, "basic-secret", "",
"A secret containing basic auth (username/password) information to connect to the broker")
cmd.Flags().StringVar(&registerCmd.BearerSecret, "bearer-secret", "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should basic-secret and bearer-secret not be basic-secret-name and bearer-secret-name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't follow that convention for flags that indicate secrets for other commands - both provision and bind just use -secret, not -secret-name

@k8s-ci-robot k8s-ci-robot merged commit eb684a9 into kubernetes-retired:master Aug 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants