-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fake client does not delete objects containing deletion timestamp #2184
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
Comments
So actually there are two possibilities here:
Glancing at the code, it should be easy enough to make this distinction: if len(oldAccessor.GetFinalizers()) > 0 && len(accessor.GetFinalizers()) == 0 { |
How did you get an object with a non-nil deletionTimestamp into the fakeclient in the first place? |
Hi @alvaroaleman, we use |
Right, so to expand on this: In general we want to be able to test reconciler behavior on deleted objects. With the fake client as it stands, we've been able to write test cases where we just init the fake client The argument of this issue is that test authors should be disallowed from getting into this state, as it throws the validity of the test case into question. Originally we were thinking that the fake client should just stealthily treat those objects the way k8s would: by deleting them from the database any time it sees them. But your comment has made us discuss and realize that it would be better to prevent getting into that situation at all. So I think we're now proposing:
That last bullet is important: We don't have equivalent k8s behavior to guide us, so we have the freedom to make it as useful as possible for test writers. If the builder ignored |
/milestone v0.15.x |
/assign @lleshchi |
/kind bug |
…ernetes libs to v0.30.0 (#3707) * go version, dep version * refactor for controller-runtime udpate * update tests, fix if statement the controller-runtime strips DeletionTimestamp from manifests on Create(). kubernetes-sigs/controller-runtime#2316 * refactor tests * remove placeholder comments * remove reconciler from WithOptions * remove DefaultNamespace cache option * remote `&& !hasGroupFinalizer` This was causing e2e tests to fail when an ingress did not have the group finalizer. The unit tests ing-1_been_deleted, and ing-6_been_deleted will need reworked due to changes in the controller-runtime that cause them to fail. * update unit tests for ctrl client/fake >0.15 controller-runtime >=0.15 does not support creating (or adding the field via Update()) objects with a DeletionTimestamp. To work around this we add an annotation `unit-test/delete` to mark the ingresses that we want to test deletion. We check for this annotation and then call Delete(). This will set the DeletionTimestamp to the current date and time so we use IgnoreOtherFields to skip then comparing want to got. relevant controller-runtime discussion/pr: - kubernetes-sigs/controller-runtime#2184 (comment) - kubernetes-sigs/controller-runtime#2316 * remove unused contexts * add DefaultNamespaces cache config * set opt.Cache.DefaultNamespaces conditionally If WatchNamespace is set to corev1.NamespaceAll we should not set DefaultNamespaces. This code assumes that only one namespace is specified for WatchNamespace. That decision was based on the help text for the flag `watch-namespace`. Related controller-runtime issue: kubernetes-sigs/controller-runtime#2628 * make crds * set go to v1.22.3
…ernetes libs to v0.30.0 (kubernetes-sigs#3707) * go version, dep version * refactor for controller-runtime udpate * update tests, fix if statement the controller-runtime strips DeletionTimestamp from manifests on Create(). kubernetes-sigs/controller-runtime#2316 * refactor tests * remove placeholder comments * remove reconciler from WithOptions * remove DefaultNamespace cache option * remote `&& !hasGroupFinalizer` This was causing e2e tests to fail when an ingress did not have the group finalizer. The unit tests ing-1_been_deleted, and ing-6_been_deleted will need reworked due to changes in the controller-runtime that cause them to fail. * update unit tests for ctrl client/fake >0.15 controller-runtime >=0.15 does not support creating (or adding the field via Update()) objects with a DeletionTimestamp. To work around this we add an annotation `unit-test/delete` to mark the ingresses that we want to test deletion. We check for this annotation and then call Delete(). This will set the DeletionTimestamp to the current date and time so we use IgnoreOtherFields to skip then comparing want to got. relevant controller-runtime discussion/pr: - kubernetes-sigs/controller-runtime#2184 (comment) - kubernetes-sigs/controller-runtime#2316 * remove unused contexts * add DefaultNamespaces cache config * set opt.Cache.DefaultNamespaces conditionally If WatchNamespace is set to corev1.NamespaceAll we should not set DefaultNamespaces. This code assumes that only one namespace is specified for WatchNamespace. That decision was based on the help text for the flag `watch-namespace`. Related controller-runtime issue: kubernetes-sigs/controller-runtime#2628 * make crds * set go to v1.22.3
* update the traffic test for ingress (#3725) * update the traffic test for ingress * make crds * prevent controller runtime complaining about SetupLogger() was never called (#3724) * Update go to v1.22, controller-runtime dependency to v0.18.2, and kubernetes libs to v0.30.0 (#3707) * go version, dep version * refactor for controller-runtime udpate * update tests, fix if statement the controller-runtime strips DeletionTimestamp from manifests on Create(). kubernetes-sigs/controller-runtime#2316 * refactor tests * remove placeholder comments * remove reconciler from WithOptions * remove DefaultNamespace cache option * remote `&& !hasGroupFinalizer` This was causing e2e tests to fail when an ingress did not have the group finalizer. The unit tests ing-1_been_deleted, and ing-6_been_deleted will need reworked due to changes in the controller-runtime that cause them to fail. * update unit tests for ctrl client/fake >0.15 controller-runtime >=0.15 does not support creating (or adding the field via Update()) objects with a DeletionTimestamp. To work around this we add an annotation `unit-test/delete` to mark the ingresses that we want to test deletion. We check for this annotation and then call Delete(). This will set the DeletionTimestamp to the current date and time so we use IgnoreOtherFields to skip then comparing want to got. relevant controller-runtime discussion/pr: - kubernetes-sigs/controller-runtime#2184 (comment) - kubernetes-sigs/controller-runtime#2316 * remove unused contexts * add DefaultNamespaces cache config * set opt.Cache.DefaultNamespaces conditionally If WatchNamespace is set to corev1.NamespaceAll we should not set DefaultNamespaces. This code assumes that only one namespace is specified for WatchNamespace. That decision was based on the help text for the flag `watch-namespace`. Related controller-runtime issue: kubernetes-sigs/controller-runtime#2628 * make crds * set go to v1.22.3 * restrict resolve resolveViaVPCENIs to fargate only (#3709) * Added helm envFrom value parameter for cluster-name (#3683) * Added helm envFrom value parameter for cluster-name * Update README.md file * Add envFrom configuration to values.yaml * Remove empty line in values.yaml * feat: disable default helm labels (#3574) * feat: disable helm labels * fix: doc * Update README.md (#3638) Remove extra / in crds --------- Co-authored-by: Luke Arntz <[email protected]> Co-authored-by: Omer Aplatony <[email protected]> Co-authored-by: Rémi BUISSON <[email protected]> Co-authored-by: Mike Wilson <[email protected]>
The fake client Get(), List(), Patch() methods do not account for objects that have been marked for deletion, allowing for viewing of and changes to objects that are expected to be deleted. The Update() method does delete the object, but I believe it should return an error, since the update of a deleted object has failed.
This is a separate issue from #138
The text was updated successfully, but these errors were encountered: