Commit b2df7e53 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #41547 from xilabao/remove-validNonResourceVerbs-in-create-role

Automatic merge from submit-queue (batch tested with PRs 41604, 41273, 41547) remove validNonResourceVerbs in create role non-resource-url is only reasonable for clusterroles
parents 7da78faf 367006be
...@@ -43,9 +43,6 @@ var ( ...@@ -43,9 +43,6 @@ var (
// Valid resource verb list for validation. // Valid resource verb list for validation.
validResourceVerbs = []string{"*", "get", "delete", "list", "create", "update", "patch", "watch", "proxy", "redirect", "deletecollection"} validResourceVerbs = []string{"*", "get", "delete", "list", "create", "update", "patch", "watch", "proxy", "redirect", "deletecollection"}
// Valid non-resource verb list for validation.
validNonResourceVerbs = []string{"get", "post", "put", "delete"}
) )
type CreateRoleOptions struct { type CreateRoleOptions struct {
...@@ -137,7 +134,7 @@ func (c *CreateRoleOptions) Validate(f cmdutil.Factory) error { ...@@ -137,7 +134,7 @@ func (c *CreateRoleOptions) Validate(f cmdutil.Factory) error {
} }
for _, v := range c.Verbs { for _, v := range c.Verbs {
if !arrayContains(validResourceVerbs, v) && !arrayContains(validNonResourceVerbs, v) { if !arrayContains(validResourceVerbs, v) {
return fmt.Errorf("invalid verb: '%s'", v) return fmt.Errorf("invalid verb: '%s'", v)
} }
} }
......
...@@ -157,6 +157,18 @@ func TestValidate(t *testing.T) { ...@@ -157,6 +157,18 @@ func TestValidate(t *testing.T) {
}, },
expectErr: true, expectErr: true,
}, },
"test-nonresource-verb": {
roleOptions: &CreateRoleOptions{
Name: "my-role",
Verbs: []string{"post"},
Resources: []schema.GroupVersionResource{
{
Resource: "pods",
},
},
},
expectErr: true,
},
"test-invalid-resource": { "test-invalid-resource": {
roleOptions: &CreateRoleOptions{ roleOptions: &CreateRoleOptions{
Name: "my-role", Name: "my-role",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment