-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add temporary "silent" flag to oc login
to allow silent logins to prevent noisy output from clusters with large amounts of prjects
#18684
Conversation
/ok-to-test |
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
@@ -68,6 +68,9 @@ type LoginOptions struct { | |||
|
|||
CommandName string | |||
RequestTimeout time.Duration | |||
|
|||
// Silent login |
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.
comment here not needed
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
@@ -405,3 +409,8 @@ func (o *LoginOptions) serverProvided() bool { | |||
func (o *LoginOptions) tokenProvided() bool { | |||
return len(o.Token) > 0 | |||
} | |||
|
|||
func (o *LoginOptions) silentLogin() bool { |
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.
not needed, just use the field value itself
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
fmt.Fprintf(o.Out, " * %s\n", p) | ||
} else { | ||
fmt.Fprintf(o.Out, " %s\n", p) | ||
if (!o.silentLogin()) { |
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.
!o.Silent
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
} else { | ||
fmt.Fprintf(o.Out, " %s\n", p) | ||
if (!o.silentLogin()) { | ||
fmt.Fprintf(o.Out, "You have access to the following projects and can switch between them with '%s project <projectname>':\n\n", o.CommandName) |
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.
@soltysh @mfojtik while I see the importance behind preventing an output of +1000 projects, perhaps it'd be a better approach to always print this line with the total number of projects You have access to 20 projects ...
. We could then either print the first 5 or 10 projects, while suggesting the use of oc projects
to retrieve the complete list. Thoughts?
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.
While limiting the output for general usage would be great, I don't feel it's a full solution to what my PR is trying to solve.
For those that are service providers and are logging in as cluster-admins or cluster-readers, they'll probably never end up using the first 20 projects so it's useless to print them out to them rather than just allowing them to disable the output of projects on login.
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.
If we added such a flag, I would expect this to print nothing and just have a non-zero exit code on failure.
@Oats87 thanks for the PR! You'll need to run |
This needs to follow existing command convention at the very least: origin/pkg/oc/admin/policy/cani.go Line 79 in 73338c4
In general I am not a fan of adding this. Just redirect to /hold |
pkg/oc/cli/cmd/login/login.go
Outdated
@@ -152,6 +153,8 @@ func (o *LoginOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args | |||
o.InsecureTLS = kcmdutil.GetFlagBool(cmd, "insecure-skip-tls-verify") | |||
o.Token = kcmdutil.GetFlagString(cmd, "token") | |||
|
|||
o.Silent = kcmdutil.GetFlagBool(cmd, "silent") |
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.
Seems unnecessary, @juanvallejo why is this filling out fields when they should be filled via the pointer stuff?
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.
We still have a number of places that "complete" fields by getting a flag value.
I don't think I'd call it an established convention yet
pkg/oc/cli/cmd/login/loginoptions.go
Outdated
} else { | ||
fmt.Fprintf(o.Out, " %s\n", p) | ||
if (!o.silentLogin()) { | ||
fmt.Fprintf(o.Out, "You have access to the following projects and can switch between them with '%s project <projectname>':\n\n", o.CommandName) |
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.
If we added such a flag, I would expect this to print nothing and just have a non-zero exit code on failure.
@Oats87 what exactly do you mean by @mfojtik @juanvallejo you guys own the CLI so I will let you decide. This specific command belongs to sig-sec, but I can live with changes if you guys feel strongly enough. |
@enj It is a temporary silent flag because it is not persistent, and thus does not persist if you do "oc login -s" then "oc login" |
In general, adding new flags is something I'd be careful about doing. |
Don't flags, by definition, only last for the invocation of the command? @juanvallejo maybe it is better to not print the project listing at all when the list has more than 100 items (print "You have access to N projects and the list has been surpressed")? That should basically leave the behavior unchanged for all users except admins (and even then admins with a sufficiently large cluster for this to come into play). |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Oats87 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
@Oats87: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Automatic merge from submit-queue. Surpress project list on login if you have access to greater than 50 projects As a compromise to #18684 we are going to surpress the project list functionality if the number of projects available to a user is greater than 50 Original RFE was at BZ #1542326 - https://bugzilla.redhat.com/show_bug.cgi?id=1542326 RFE is within that BZ, but there was a compromise.
This simply adds a silent flag to the
oc login
command to prevent oc from spitting out a ton of extraneous data when logging into a cluster that has a lot of projects accessible to a user.For BZ #1542326 - https://bugzilla.redhat.com/show_bug.cgi?id=1542326
RFE is within that BZ