-
Notifications
You must be signed in to change notification settings - Fork 407
NO-JIRA: Display whoami information as JSON or YAML #1324
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
base: main
Are you sure you want to change the base?
Conversation
/retest-required |
/retest-required |
Signed-off-by: Christian Hernandez <[email protected]> changing to output of json or yaml Signed-off-by: Christian Hernandez <[email protected]> updated to use output of yaml or json Signed-off-by: Christian Hernandez <[email protected]> added the GVK to the output Signed-off-by: Christian Hernandez <[email protected]>
26f79b8
to
790d0f4
Compare
/retest-required |
1 similar comment
/retest-required |
/test e2e-aws-ovn-serial |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: christianh814 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@christianh814: The following tests failed, say
Full PR test history. Your PR dashboard. 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. |
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
/remove-lifecycle stale |
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
Stale issues rot after 30d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle rotten |
/remove-lifecycle rotten |
/remove-lifecycle stale |
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
/remove-lifecycle stale. |
Stale issues rot after 30d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle rotten |
/remove-lifecycle rotten |
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
/remove-lifecycle stale |
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
/remove-lifecycle stale |
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
/remove-lifecycle stale |
/retitle NO-JIRA: Display whoami information as JSON or YAML @ardaguclu PTAL |
@christianh814: This pull request explicitly references no jira issue. In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
@vrutkovs fyi jira exists here: https://issues.redhat.com/browse/RFE-3594 should we use that? |
@vrutkovs JIRA was created 2 years ago https://issues.redhat.com/browse/RFE-3594 |
This RFE seems deferred, so we'll need a bug or a task ticket for this. In any case, JIRA ticket here is required if we want to backport it - and it can be done later |
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.
Thank you for this PR. However, SelfSubjectReview takes precedence over User object in OpenShift. So that this PR needs to be modified accordingly.
@@ -153,14 +164,34 @@ func (o *WhoAmIOptions) Run() error { | |||
} | |||
fmt.Fprintf(o.Out, "%s\n", consoleUrl) | |||
return nil | |||
} | |||
case o.Output == "yaml": | |||
u, err := o.UserInterface.Users().Get(context.TODO(), "~", metav1.GetOptions{}) |
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.
SelfSubjectReview needs to take precedence over UserInterface (logic
Lines 88 to 107 in 093ad87
res, err := o.AuthV1Client.SelfSubjectReviews().Create(context.TODO(), &v1.SelfSubjectReview{}, metav1.CreateOptions{}) | |
if err == nil { | |
me := &userv1.User{ | |
ObjectMeta: metav1.ObjectMeta{ | |
Name: res.Status.UserInfo.Username, | |
}, | |
Groups: res.Status.UserInfo.Groups, | |
} | |
fmt.Fprintf(o.Out, "%s\n", me.Name) | |
return me, nil | |
} else { | |
klog.V(2).Infof("selfsubjectreview request error %v, falling back to user object", err) | |
} | |
me, err := o.UserInterface.Users().Get(context.TODO(), "~", metav1.GetOptions{}) | |
if err == nil { | |
fmt.Fprintf(o.Out, "%s\n", me.Name) | |
} | |
return me, err |
WhoAmI
function.
} | ||
fmt.Fprintf(o.Out, "%s\n", string(y)) | ||
return nil | ||
case o.Output == "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.
We can use built-in printing flags to print yaml and json files. Example, https://github.com/kubernetes/kubectl/blob/5ff92a69e3ecb06912d5f468186d458bf610244e/pkg/cmd/auth/whoami.go#L64
@@ -47,6 +49,8 @@ type WhoAmIOptions struct { | |||
ShowContext bool | |||
ShowServer bool | |||
ShowConsoleUrl bool | |||
ShowGroups 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.
Unused and not related to this PR?
Added an option
-o
or--output
that displays the user information in YAML or JSON.Closes: #1323
Signed-off-by: Christian Hernandez [email protected]