Java-client: Best way to check operation delete operation completion?

11/22/2019

I'm wondering what is the best way to confirm a delete operation is successful via the Java client? Just because we get a successful status after the API call does not mean the resources, in my case a pod, has been finally deleted.

Currently my approach to do a delete api call, then to do a list pods with watch waiting for a delete event. This feels a bit brittle to me.

I have a couple questions:

  1. Do watches on delete calls work? I tried to add one but all my items were null. Which is why I do a list call afterwards.
  2. Is there a more streamlined way to check for the complete deletion of a pod?

Below is a rough example of what I've been trying.

     clientConfig.deleteCollectionNamespacedPod(entity.getNamespace(), null, null, null,
             String.format(NAME_FIELD_SELECTOR, entity.getName()), null, null, null, null, null);

     Call call = clientConfig.listNamespacedPodCall(entity.getNamespace(), null, null, null,
             String.format(NAME_FIELD_SELECTOR, entity.getName()), null, null, null, null, Boolean.TRUE,
             null, null);

     Watch<V1Pod> watch = Watch.createWatch(BaseClient.newBaseClient(clientConfig), call, new TypeToken<Watch.Response<V1Pod>>() {
     }.getType());

     for (Watch.Response<V1Pod> item : watch) {
        if (item.type == "DELETED") {
           // return that the deletion of the object was successful 
        }
     }
-- Cain
kubernetes

0 Answers