-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
deep copy fake client actions to avoid accidental mutation #60709
deep copy fake client actions to avoid accidental mutation #60709
Conversation
Fewer problems than I expected actually. |
@@ -324,6 +324,7 @@ type Action interface { | |||
GetResource() schema.GroupVersionResource | |||
GetSubresource() string | |||
Matches(verb, resource string) bool | |||
DeepCopy() Action |
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.
Given that you run into an issue due to a mutation, maybe you could add some godoc on this method explaining why/when to use it?
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.
Given that you run into an issue due to a mutation, maybe you could add some godoc on this method explaining why/when to use it?
Sure, but it is called by the invoking function. Users should never see it.
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.
Given that you run into an issue due to a mutation, maybe you could add some godoc on this method explaining why/when to use it?
done
3e2ba6b
to
9ef99d1
Compare
/retest |
/cc @yliaog |
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.
/lgtm
/retest |
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.
/approve on the metrics bits
The rest looks reasonable too, modulo that wonderful TODO
func (a GenericActionImpl) DeepCopy() Action { | ||
return GenericActionImpl{ | ||
ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl), | ||
// TODO this is wrong, but no worse than before |
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.
these are the quality comments I like to see during code review.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, DirectXMan12, soltysh 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 |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here. |
I just got bit by this downstream. Without a deep copy it is possible accidentally mutate the thing you created, thus invalidating your testing. It's particularly nasty inside of a controller doing a loop on objects, making refs to them, and creating. This works running in an actual process since we serialize and write, but fails unit tests since there is no serialization step.
@kubernetes/sig-api-machinery-bugs