-
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
Fakeclient: Patching an object that has allowUnconditionalUpdate=false where the patched version has no RV should succeed #2678
Comments
Actually, at least that precise testcase is wrong as it will end up generating a patch that explicitly sets ResourceVersion to |
\# Context This PR should fix a bug kubernetes-sigs#2678 where patching a resource would throw a conflict error when the new object doesn't specify any RV. - Because the new RV is an null, an error is thrown here: https://github.com/kubernetes-sigs/controller-runtime/blob/01de80b092778fd35abd9e2371d54ce0953d4613/pkg/client/fake/client.go#L429-L430 - The RV is nil, because the computed patch between the old and new accessor doesn't include resourceVersion: - https://github.com/evanphx/json-patch/blob/v5.9.0/v5/merge.go#L253-L273 - Witch is used by `client.MergeFrom()`: https://github.com/kubernetes-sigs/controller-runtime/blob/v0.17.2/pkg/client/patch.go#L150-L152 \# Changes - Fix patch by setting the new accessors' RV to the old accessors' RV. - Add test to ensure the correct behavior
\# Context This PR should fix a bug kubernetes-sigs#2678 where patching a resource would throw a conflict error when the new object doesn't specify any RV. - Because the new RV is an empty string, an error is thrown here: https://github.com/kubernetes-sigs/controller-runtime/blob/01de80b092778fd35abd9e2371d54ce0953d4613/pkg/client/fake/client.go#L429-L430 - The RV is nil, because the computed patch between the old and new accessor doesn't include resourceVersion: - https://github.com/evanphx/json-patch/blob/v5.9.0/v5/merge.go#L253-L273 - Witch is used by `client.MergeFrom()`: https://github.com/kubernetes-sigs/controller-runtime/blob/v0.17.2/pkg/client/patch.go#L150-L152 \# Changes - Fix patch by setting the new accessors' RV to the old accessors' RV. - Add test to ensure the correct behavior
Talked to Alvaro. Just to clarify. The goal is that the fake client allows a patch which sets resourceVersion to nil. Verified that the real apiserver behaves the same via envtest: It("should update an existing object non-namespace object from a go struct", func() {
cl, err := client.New(cfg, client.Options{})
Expect(err).NotTo(HaveOccurred())
Expect(cl).NotTo(BeNil())
node, err := clientset.CoreV1().Nodes().Create(ctx, node, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())
original := node.DeepCopy()
By("updating the object")
node.Annotations = map[string]string{"foo": "bar"}
node.ObjectMeta.ResourceVersion = ""
err = cl.Patch(context.TODO(), node, client.MergeFrom(original))
Expect(err).NotTo(HaveOccurred())
By("validate updated Node had new annotation")
actual, err := clientset.CoreV1().Nodes().Get(ctx, node.Name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(actual).NotTo(BeNil())
Expect(actual.Annotations["foo"]).To(Equal("bar"))
}) |
This got fixed in #2725, closing |
Easiest to show with a testcase, the following test should pass but does not:
We never noticed this, because all the tests use built-in resoruces and they all allowUnconditionalUpdate
The text was updated successfully, but these errors were encountered: