Allow create.specialVerbs to be customized
Kubernetes-commit: 9b2f24aee0668ef54e7f51acc79e51b93f1aedb3
This commit is contained in:
parent
f6fcb7d932
commit
88ea823a7a
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue