Allow create.specialVerbs to be customized

This commit is contained in:
Ross Peoples 2021-12-16 13:08:28 -06:00
parent eb43b41cfd
commit 9b2f24aee0
2 changed files with 35 additions and 0 deletions

View File

@ -112,6 +112,14 @@ var (
}
)
// AddSpecialVerb allows the addition of items to the `specialVerbs` map for non-k8s native resources.
func AddSpecialVerb(verb string, gr schema.GroupResource) {
if resources, ok := specialVerbs[verb]; ok {
resources = append(resources, gr)
specialVerbs[verb] = resources
}
}
// ResourceOptions holds the related options for '--resource' option
type ResourceOptions struct {
Group string

View File

@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/rest/fake"
@ -677,3 +678,29 @@ func TestComplete(t *testing.T) {
}
}
}
func TestAddSpecialVerb(t *testing.T) {
resource := schema.GroupResource{
Group: "my.custom.io",
Resource: "things",
}
AddSpecialVerb("use", resource)
found := false
resources, ok := specialVerbs["use"]
if !ok {
t.Errorf("expected resources for verb: use, found none\n")
}
for _, res := range resources {
if reflect.DeepEqual(resource, res) {
found = true
break
}
}
if !found {
t.Errorf("expected resource:\n%v\nnot found", resource)
}
}