-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
[WIP] Fix hardcoded string, add fetch validResource from APIServer #51324
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: shiywang Assign the PR to them by writing Associated issue: 51023 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 |
const validResources = `Valid resource types include: | ||
|
||
* all | ||
* certificatesigningrequests (aka 'csr') |
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.
some of are not belong to core/legacy api group, remove them ?
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.
some of are not belong to core/legacy api group, remove them ?
I would
/assign @deads2k |
db78046
to
913a5f4
Compare
resourceMap := make(map[string]metav1.APIResource) | ||
var keys []string | ||
discoveryClient, err := f.clientAccessFactory.DiscoveryClient() | ||
if err == nil { |
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.
invert the if to reduce nesting
discoveryClient, err := f.clientAccessFactory.DiscoveryClient() | ||
if err == nil { | ||
apiResList, err := discoveryClient.ServerResources() | ||
if err == nil { |
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.
invert if to reduce nesting
if err == nil { | ||
for _, apiResources := range apiResList { | ||
for _, apiRes := range apiResources.APIResources { | ||
if !strings.Contains(apiRes.Name, "/") && apiRes.Name != "apiservices" { |
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.
apiservices are resources too! :)
@@ -489,3 +490,95 @@ func (f *ring1Factory) OpenAPISchema(cacheDir string) (openapi.Resources, error) | |||
// Delegate to the OpenAPIGetter | |||
return f.openAPIGetter.getter.Get() | |||
} | |||
|
|||
func (f *ring1Factory) ValidResourcesFromDiscoveryClient() string { |
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 think this method ought to return []string
of just the resources strings
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.
resources strings only contain resource name ? or we can directly return sorted []APIResources
then write a wrapper/helper function to concatenate those APIResource.Name
and APIREsource.ShortNames
to string output ?
row := "Valid resource types include:\n\n * all\n" | ||
for _, k := range keys { | ||
if k == "clusters" { | ||
row = row + " * clusters (valid only for federation apiservers)\n" |
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'd do this purely on discovery. If they're in the discovery list, they don't need qualification
@kubernetes/sig-cli-misc |
bd1c7c2
to
f098b7a
Compare
Adding do-not-merge/release-note-label-needed because the release note process has not been followed. |
f098b7a
to
36b8fab
Compare
@shiywang: The following tests 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. |
@shiywang PR needs rebase |
@@ -113,7 +113,7 @@ func NewCmdAnnotate(f cmdutil.Factory, out io.Writer) *cobra.Command { | |||
cmd := &cobra.Command{ | |||
Use: "annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]", | |||
Short: i18n.T("Update the annotations on a resource"), | |||
Long: annotateLong, | |||
Long: templates.LongDesc(fmt.Sprintf(annotateLong, f.ValidResourcesFromDiscoveryClient())), |
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 don't think we should ever talk to the server to display help. I'd rather see a dedicated command for displaying available resources, and reference that command in this help string
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 wrote a proposal for this feature, ptal kubernetes/community#1017
This PR hasn't been active in 90 days. Closing this PR. Please reopen if you would like to work towards merging this change, if/when the PR is ready for the next round of review. cc @deads2k @fabianofranz @ghodss @shiywang You can add 'keep-open' label to prevent this from happening again, or add a comment to keep it open another 90 days |
Fixes #51023
if DiscoveryClient failed, return previous hard coded string.
this change may make
kubectl get/annotate.. -h
a little slow first time, @deads2k do you think it's acceptable ?before:
after: