Merge pull request #107083 from deejross/create-special-verbs

Allow `create.specialVerbs` to be customized

Kubernetes-commit: 8c2ee3c42228f19b29526f7fa5254e137e209502
This commit is contained in:
Kubernetes Publisher 2021-12-20 10:13:07 -08:00
commit 8b3da612e5
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)
}
}