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
Check for required name parameter in dynamic client #75072
Check for required name parameter in dynamic client #75072
Conversation
Hi @lblackstone. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
@@ -216,6 +217,9 @@ func (c *dynamicResourceClient) DeleteCollection(opts *metav1.DeleteOptions, lis | |||
} | |||
|
|||
func (c *dynamicResourceClient) Get(name string, opts metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error) { | |||
if name == "" { | |||
return nil, fmt.Errorf("name is required") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this validation should also be applied to Patch
, Delete
, Update
, UpdateStatus
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated Patch
and Delete
. The other ones didn't have a name
parameter to validate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update/updatestatus can use accessor.GetName()
create should also validate name if len(subresources) > 0
6cfac3f
to
ec958c4
Compare
/assign @caesarxuchao |
/lgtm |
The Create, Delete, Get, Patch, Update and UpdateStatus methods in the dynamic client all expect the name parameter to be non-empty, but did not validate this requirement, which could lead to a panic. Add explicit checks to these methods.
ec958c4
to
a9cba03
Compare
I rebased on master and added the name check to |
@@ -102,6 +103,9 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, opts meta | |||
return nil, err | |||
} | |||
name = accessor.GetName() | |||
if len(name) == 0 { | |||
return nil, fmt.Errorf("name is required") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name can be empty, if we set the generateName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not when dealing with a subresource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh tricked. it's subresource.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lblackstone, liggitt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The |
/retest |
/retest Review the full test history for this PR. Silence the bot with an |
…2-upstream-release-1.13 Automated cherry pick of #75072: Check for required name parameter in dynamic client
…2-upstream-release-1.14 Automated cherry pick of #75072: Check for required name parameter in dynamic client
What type of PR is this?
/kind bug
What this PR does / why we need it:
The dynamic client in the client-go library was not validating that the required
name
parameter was non-empty for theDelete
,Get
, andPatch
requests. If an empty string was provided, these methods would panic.This PR adds a check for empty string and returns an error rather than panicking.
Which issue(s) this PR fixes:
Fixes #75069
Special notes for your reviewer:
Does this PR introduce a user-facing change?: