kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

DeletionTimestamp and Finalizer support in Mock server

Open scrocquesel opened this issue 3 years ago • 3 comments

Is your enhancement related to a problem? Please describe

I'm writing an operator and would like to test how it behaves when deleting a resource. In CRUD mode, when a resource is deleted, it is remove even if finalizers is not empty.

Describe the solution you'd like

I expect delete to update the resource with a deletionTimestamp if finalizers collection is not empty. When the operator will remove its finalizer and update the CR, if the finalizers collection is empty, the resource should be deleted.

I should be able to wait for the resource to be deleted (wait while get CR is not null) and assert the operator does its cleanup job.

Describe alternatives you've considered

I tried to update the resource with edit to set a deletionTimestamp but is seems to be not saved.

client.resources(CRD.class).inNamespace("foo").withName("bar").edit(p -> {
    p.getMetadata().setDeletionTimestamp("2022-02-06T14:21:44.719489Z");
    return p;
});

what works is to replace the CR.

var cr = client.resources(CRD.class).inNamespace("foo").withName("bar").get();
cr.getMetadata().setDeletionTimestamp("2022-02-06T14:21:44.719489Z");
client.resource(cr).createOrReplace();

Additional context

No response

scrocquesel avatar Feb 06 '22 15:02 scrocquesel

+1 on this, I was just writing a test and was surprised that my CR with a finalizer had actually been deleted

amydentremont avatar Mar 31 '22 20:03 amydentremont

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

stale[bot] avatar Jun 29 '22 22:06 stale[bot]

Any news on this ? As Red Hat announced a Java Operator SDK preview, testing finalizers and dependent resources deletion will become a common use case: Write Kubernetes with the Java Operator SDK | Red Hat Developer

derlin avatar Aug 23 '22 14:08 derlin