Unverified Commit c338209e authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #57500 from niuzhenguo/unique-resource-mappings

Automatic merge from submit-queue (batch tested with PRs 57500, 58840, 58883). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Make REST mappings for resources a unique list This ensures the mappings list for resources(shortcuts, plural) unique, instead of doing multiple requests to server for the same resource. **What this PR does / why we need it**: Treat resource shortcuts, plurals the same thing on kubectl side instead of doing multiple requests to servers, and outputs should not duplicate entires. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #57498 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
parents 462d9f22 6be1b975
...@@ -622,11 +622,17 @@ func (b *Builder) resourceMappings() ([]*meta.RESTMapping, error) { ...@@ -622,11 +622,17 @@ func (b *Builder) resourceMappings() ([]*meta.RESTMapping, error) {
return nil, fmt.Errorf("you may only specify a single resource type") return nil, fmt.Errorf("you may only specify a single resource type")
} }
mappings := []*meta.RESTMapping{} mappings := []*meta.RESTMapping{}
seen := map[schema.GroupVersionKind]bool{}
for _, r := range b.resources { for _, r := range b.resources {
mapping, err := b.mappingFor(r) mapping, err := b.mappingFor(r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// This ensures the mappings for resources(shortcuts, plural) unique
if seen[mapping.GroupVersionKind] {
continue
}
seen[mapping.GroupVersionKind] = true
mappings = append(mappings, mapping) mappings = append(mappings, mapping)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment