-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
"os" | ||
"path" | ||
"sort" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
|
@@ -489,3 +490,69 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. I think this method ought to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resources strings only contain resource name ? or we can directly return sorted |
||
resourceMap := make(map[string]metav1.APIResource) | ||
var keys []string | ||
discoveryClient, err := f.clientAccessFactory.DiscoveryClient() | ||
if err != nil { | ||
return validLegacyGroupResources | ||
} | ||
apiResList, err := discoveryClient.ServerResources() | ||
if err != nil { | ||
return validLegacyGroupResources | ||
} | ||
|
||
for _, apiResources := range apiResList { | ||
for _, apiRes := range apiResources.APIResources { | ||
if !strings.Contains(apiRes.Name, "/") { | ||
if _, ok := resourceMap[apiRes.Name]; !ok { | ||
resourceMap[apiRes.Name] = apiRes | ||
keys = append(keys, apiRes.Name) | ||
} | ||
} | ||
} | ||
} | ||
sort.Strings(keys) | ||
row := "Valid resource types include:\n\n * all\n" | ||
for _, k := range keys { | ||
//add resource name | ||
row = row + fmt.Sprintf(" * %s ", resourceMap[k].Name) | ||
//concatenate shortnames | ||
if len(resourceMap[k].ShortNames) > 0 { | ||
row = row + " (aka " | ||
for i, shortName := range resourceMap[k].ShortNames { | ||
row = row + "'" + shortName + "'" | ||
if i < len(resourceMap[k].ShortNames)-1 { | ||
row = row + "," | ||
} | ||
} | ||
row = row + ")" | ||
} | ||
//add newline | ||
row = row + "\n" | ||
} | ||
return row | ||
} | ||
|
||
const validLegacyGroupResources = `Valid resource types include: | ||
|
||
* all | ||
* bindings | ||
* componentstatuses (aka 'cs') | ||
* configmaps (aka 'cm') | ||
* endpoints (aka 'ep') | ||
* events (aka 'ev') | ||
* limitranges (aka 'limits') | ||
* namespaces (aka 'ns') | ||
* nodes (aka 'no') | ||
* persistentvolumeclaims (aka 'pvc') | ||
* persistentvolumes (aka 'pv') | ||
* pods (aka 'po') | ||
* podtemplates | ||
* replicationcontrollers (aka 'rc') | ||
* resourcequotas (aka 'quota') | ||
* secrets | ||
* serviceaccounts (aka 'sa') | ||
* services (aka 'svc') | ||
` |
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