Skip to content
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

Improve cluster|project list-members subcommands #399

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

pmatseykanets
Copy link
Contributor

@pmatseykanets pmatseykanets self-assigned this Oct 28, 2024
@pmatseykanets pmatseykanets requested a review from a team as a code owner October 28, 2024 17:06
@pmatseykanets pmatseykanets marked this pull request as draft October 28, 2024 17:07
@alegrey91 alegrey91 self-requested a review October 28, 2024 17:13
@pmatseykanets pmatseykanets marked this pull request as ready for review October 28, 2024 22:15
Copy link

@bigkevmcd bigkevmcd left a comment

Choose a reason for hiding this comment

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

Looks good to me, some minor nits and one thing that I think should be fixed.

func getMemberNameFromPrincipal(principals principalGetter, principalID string) string {
principal, err := principals.ByID(url.PathEscape(principalID))
if err != nil {
principal = parsePrincipalID(principalID)

Choose a reason for hiding this comment

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

Should this maybe only happen if it's not found? Feels a little odd to show the user details if we got a network error communicating with the cluster?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. This is deliberate. Up until rancher/rancher#47702 this endpoint always returned 500. And the fix is not backported yet. But more importantly there is no reason to break the whole command (that lists {C|P}RTB's) just because we can't look up a principal. We can do the next best thing - parse the principal name and produce the output. More over I think that's what UI should do too.

cmd/common_test.go Outdated Show resolved Hide resolved
cmd/common_test.go Outdated Show resolved Hide resolved

err := listProjectMembers(cctx, &out, userConfig, prtbs, principals)
require.NoError(t, err)
require.NotEmpty(t, out)

Choose a reason for hiding this comment

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

nit: you don't need require.NotEmpty(t, out) as you have a deeper assertion below.

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 was intentional. There is no need to do any other work if the output is empty. This assertion is cheap.

alegrey91
alegrey91 previously approved these changes Oct 29, 2024
Copy link

@alegrey91 alegrey91 left a comment

Choose a reason for hiding this comment

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

LGTM

cmd/common.go Outdated Show resolved Hide resolved
Copy link
Contributor

@enrichman enrichman left a comment

Choose a reason for hiding this comment

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

Love the changes, and tests. Thanks!

FocusedProject() string
}

func listClusterMembers(ctx *cli.Context, out io.Writer, config userConfig, crtbs crtbLister, principals principalGetter) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great change for testability

Copy link
Contributor

@crobby crobby left a comment

Choose a reason for hiding this comment

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

lgtm, addresses the original issue and makes things a lot better overall...and adds tests.

@pmatseykanets
Copy link
Contributor Author

Do not merge: this is slated for v2.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants