mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
ShortcutExpander has been extended in a way that it will examine a hardcoded list of tuples anticipated from the server when
searching for an alternative name for the resource. Note that the list is ordered and the first match will yield the extended resource's name. One important thing to highlight is that the ShortcutExpander will fall back to PriorityRestMaper to determine the group for the resource. Also this PR introduces a new shortcut namely sc which will resolve to storageclasses within storage.k8s.io group In addition the type of kubectl.ShortForms has been changed to ResourceShortcuts struct. It has got a brand new name, it was also extended and ordered by group.
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
func TestReplaceAliases(t *testing.T) {
|
||||
@@ -44,6 +45,16 @@ func TestReplaceAliases(t *testing.T) {
|
||||
arg: "all,secrets",
|
||||
expected: "pods,replicationcontrollers,services,statefulsets,horizontalpodautoscalers,jobs,deployments,replicasets,secrets",
|
||||
},
|
||||
{
|
||||
name: "sc-resolves-to-storageclasses",
|
||||
arg: "sc",
|
||||
expected: "storageclasses",
|
||||
},
|
||||
{
|
||||
name: "storageclasses-no-replacement",
|
||||
arg: "storageclasses",
|
||||
expected: "storageclasses",
|
||||
},
|
||||
}
|
||||
|
||||
mapper := NewShortcutExpander(testapi.Default.RESTMapper(), nil)
|
||||
@@ -59,3 +70,30 @@ func TestReplaceAliases(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestKindFor(t *testing.T) {
|
||||
tests := []struct {
|
||||
in schema.GroupVersionResource
|
||||
expected schema.GroupVersionKind
|
||||
}{
|
||||
{
|
||||
in: schema.GroupVersionResource{Group: "storage.k8s.io", Version: "", Resource: "sc"},
|
||||
expected: schema.GroupVersionKind{Group: "storage.k8s.io", Version: "v1beta1", Kind: "StorageClass"},
|
||||
},
|
||||
{
|
||||
in: schema.GroupVersionResource{Group: "", Version: "", Resource: "sc"},
|
||||
expected: schema.GroupVersionKind{Group: "storage.k8s.io", Version: "v1beta1", Kind: "StorageClass"},
|
||||
},
|
||||
}
|
||||
|
||||
mapper := NewShortcutExpander(testapi.Default.RESTMapper(), nil)
|
||||
|
||||
for i, test := range tests {
|
||||
ret, err := mapper.KindFor(test.in)
|
||||
if err != nil {
|
||||
t.Errorf("%d: unexpected error returned %s", i, err.Error())
|
||||
}
|
||||
if ret != test.expected {
|
||||
t.Errorf("%d: unexpected data returned %#v, expected %#v", i, ret, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user