Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove validNonResourceVerbs in create role #41547

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions pkg/kubectl/cmd/create_role.go
Expand Up @@ -43,9 +43,6 @@ var (

// Valid resource verb list for validation.
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 {
Expand Down Expand Up @@ -137,7 +134,7 @@ func (c *CreateRoleOptions) Validate(f cmdutil.Factory) error {
}

for _, v := range c.Verbs {
if !arrayContains(validResourceVerbs, v) && !arrayContains(validNonResourceVerbs, v) {
if !arrayContains(validResourceVerbs, v) {
return fmt.Errorf("invalid verb: '%s'", v)
}
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/kubectl/cmd/create_role_test.go
Expand Up @@ -157,6 +157,18 @@ func TestValidate(t *testing.T) {
},
expectErr: true,
},
"test-nonresource-verb": {
roleOptions: &CreateRoleOptions{
Name: "my-role",
Verbs: []string{"post"},
Resources: []schema.GroupVersionResource{
{
Resource: "pods",
},
},
},
expectErr: true,
},
"test-invalid-resource": {
roleOptions: &CreateRoleOptions{
Name: "my-role",
Expand Down