-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fake Client .Update updates both spec and status? #2230
Comments
Hey @vincepri @alvaroaleman, sorry to ping you here. I also found the same weird behavior from |
It depends if resources have or do not have a status subresource and today there is no way in the fake client to figure that out. Never updating the status would be just as wrong and also breaking. Ideas on how to improve this are always welcome :) |
[Only for CRDs] I wonder if it's an option to change behavior if the corresponding CRD has also been added to the fake client. With that information the fake client could handle the update correctly Thinking about this a bit more, it's a bit strange and a difference to Kubernetes / envtest that the fake client does not require to add the CRDs before CRs can be added. But I think changing the fake client to require CRDs would break to many users of fake client. |
I'm not sure I understand. We're using the fake client like this:
If I do a I guess there's some other way of interacting with it where you don't have to register the type? Regardless, for our case, we're primarily concerned with the behavior for registered CRDs. If we changed the fake client |
I think what @sbueringer was talking about is if the CRD object has been added to the fakeclient rather than the type registered in the scheme, as the CRD has the setting if the |
Yes exactly! If you write your unit tests with env test instead of fake client or move unit tests from fake client to envtest the first thing you have to do is actually deploy your CRDs :). So it doesn't seem to far of to make the fake client more realistic in the case the corresponding CRD was actually added to the fake client. |
Okay cool. That all makes sense to me. I thought the behavior was different with Patch, but it looks to be the same (I was using Patch incorrectly when I was checking the behavior). So is my understanding correct that right now when you update a resource in any way using the fake client, whether a CRD is registered or not, all fields are potentially updatable (regardless of whether it includes a subresource), with the entire object being replaced by Update and Patch updating whatever's in the patch)? And what we're talking about here is that we could change the behavior to be more in line with the client if someone has added the CRDs to the fake client because then we could inspect the CRD to know what fields on the CR are subresources. Then, we could basically strip the subresources out when doing the update/patch to mimic the behavior of the real client? A few remaining questions:
|
2: Is this something that is likely to be done soon (the CRD-specific behavior)? If not, would you be open to me writing a PR? Sure |
Took a stab at this: #2259 |
Sorry, a dumb question, this might be a breaking change, right? Since I would imagine some unit tests might break if we introduce this change. |
Yes it is, which is why the corresponding PR is marked as breaking and will be highlighted as such in the release notes |
The fake client's
Update
call updates both the spec and status of the object.This is different from how the real client behaves. This can lead to situations where someone writes a unit test, the unit test passes, but the behavior will be different when dealing with a real client.
Is this known/intended? It seems like the fake client should update the spec and replace the status with whatever the value is on the "server".
The text was updated successfully, but these errors were encountered: