Closed
Description
I am going to use java-operator-sdk to implement my own operator, but I found that when I implemented the Cleaner method, I found that when deleting a pod, the cleanup method was not called, and the k8s pod would not be deleted, only in The cleanup method will be called after restarting the application, and the pod will be deleted. My implementation is as follows. Is my implementation wrong?
@ControllerConfiguration
public class CloudIdeOperator implements Reconciler<Pod>, Cleaner<Pod> {
private volatile int count = 0;
private volatile int count2 = 0;
@Override
public DeleteControl cleanup(Pod pod, Context<Pod> context) {
count2++;
System.out.println("cleanUp times:" + count2+" "+ pod.getMetadata().getName() + ": " + pod.getStatus().getPodIP());
return DeleteControl.defaultDelete();
}
@Override
public UpdateControl<Pod> reconcile(Pod pod, Context<Pod> context) throws Exception {
System.out.println(pod.getMetadata().getName() + ": " + pod.getStatus().getPodIP());
count++;
System.out.println("crete pod times:" + count);
return UpdateControl.noUpdate();
}
}
calll method
public static void main(String[] args) {
KubernetesClient client = new DefaultKubernetesClient();
Operator operator = new Operator(client);
operator.register(new CloudIdeOperator());
operator.installShutdownHook();
operator.start();
// operator.stop();
}