Merge pull request #58741 from dixudx/fix_kubectl_alias_group

Automatic merge from submit-queue (batch tested with PRs 58302, 58782, 58555, 58741). 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>.

use containing API group when resolving shortname from discovery

**What this PR does / why we need it**:
kubectl does not use containing API group when resolving shortname from discovery 

**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 #58695

**Special notes for your reviewer**:
/assign @liggitt 
/cc @nikhita @zjj2wry 
**Release note**:

```release-note
use containing API group when resolving shortname from discovery
```
pull/6/head
Kubernetes Submit Queue 2018-01-25 11:43:57 -08:00 committed by GitHub
commit 617c87ba06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -115,6 +115,7 @@ func (e shortcutExpander) expandResourceShortcut(resource schema.GroupVersionRes
}
if resource.Resource == item.ShortForm.Resource {
resource.Resource = item.LongForm.Resource
resource.Group = item.LongForm.Group
return resource
}
}

View File

@ -46,7 +46,7 @@ func TestReplaceAliases(t *testing.T) {
{
name: "hpa-priority",
arg: "hpa",
expected: schema.GroupVersionResource{Resource: "superhorizontalpodautoscalers"},
expected: schema.GroupVersionResource{Resource: "superhorizontalpodautoscalers", Group: "autoscaling"},
srvRes: []*metav1.APIResourceList{
{
GroupVersion: "autoscaling/v1",
@ -68,6 +68,31 @@ func TestReplaceAliases(t *testing.T) {
},
},
},
{
name: "resource-override",
arg: "dpl",
expected: schema.GroupVersionResource{Resource: "deployments", Group: "foo"},
srvRes: []*metav1.APIResourceList{
{
GroupVersion: "foo/v1",
APIResources: []metav1.APIResource{
{
Name: "deployments",
ShortNames: []string{"dpl"},
},
},
},
{
GroupVersion: "extension/v1beta1",
APIResources: []metav1.APIResource{
{
Name: "deployments",
ShortNames: []string{"deploy"},
},
},
},
},
},
}
ds := &fakeDiscoveryClient{}