diff --git a/pkg/cmd/create/create_role.go b/pkg/cmd/create/create_role.go index ec7d5bec..20b8876f 100644 --- a/pkg/cmd/create/create_role.go +++ b/pkg/cmd/create/create_role.go @@ -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 diff --git a/pkg/cmd/create/create_role_test.go b/pkg/cmd/create/create_role_test.go index 8ed5b71f..8cc55037 100644 --- a/pkg/cmd/create/create_role_test.go +++ b/pkg/cmd/create/create_role_test.go @@ -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) + } +}