Closed
Description
Feature request
I have built a Kubernetes Operator based in Java Operator SDK v4.3.1 that handles a primary custom resource and several managed dependent resources.
One of the dependent resources is a Pod
running a "critical" process.
If somehow (user/application/crash) this dependent resource is deleted externally, the primary custom resource should be marked for deletion.
What did you do?
This is an implementation example to describe the scenario:
@ControllerConfiguration(
name = "myresourcereconciler",
dependents = {
@Dependent(
name = "configmapmependentresource",
type = ConfigMapDependentResource.class,
reconcilePrecondition = ConfigMapReconcileCondition.class
),
@Dependent(
name = "criticalpoddependentresource",
type = CriticalPodDependentResource.class
),
@Dependent(
name = "servicedependentresource",
type = ServiceDependentResource.class
)
}
)
public class MyResourceReconciler implements Reconciler<MyResource>, Cleaner<MyResource> {
@Override
public UpdateControl<MyResource> reconcile(MyResource resource, Context<MyResource> context) throws Exception {
//Reconcile implementation
return updatedResourceStatus != null ? UpdateControl.patchStatus(updatedResource) : UpdateControl.noUpdate();
}
@Override
public DeleteControl cleanup(MyResource resource, Context<MyResource> context) {
//Cleanup implementation
return DeleteControl.defaultDelete();
}
}
...
@KubernetesDependent(labelSelector = MyResource .LABEL_SELECTOR)
public class CriticalPodDependentResource extends CRUDKubernetesDependentResource<Pod, MyResource > {
@Override
protected Pod desired(MyResource primary, Context<MyResource> context) {
// Desired Pod creation
return pod;
}
@Override
public void delete(MyResource primary, Context<MyResource> context) {
//Expected this operation to be called on dependent resource external delete event
context.getClient().resource(primary).delete();
}
}
What did you expect to see?
CriticalPodDependentResource.delete()
operation called on dependent resource external deletion.
What did you see instead? Under which circumstances?
After deleting the critical dependent resource externally, the primary custom resource reconcile operation is triggered, and it was kind of expected...
Metadata
Metadata
Assignees
Labels
No labels