Check Status of replicas of StatefulState using io.fabric8.kubernetes

3/21/2019

I am terminating pods in a stateful state using io.fabric8.kubernetes client as

client
        .inNamespace(namespace)
        .pods()
        .withLabel("xx", "xxx")
        .delete()

How can check if the StatefulSet is recovered back ?

What I am trying :

StatefulSet statefulSet = client
            .pods()
            .inNamespace("namespace-xxx")
            .statefulSets()
            .inNamespace(namespace)
            .withName("statefulset-name")
            .get();

StatefulSetStatus status = statefulSet.getStatus();
StatefulSetSpec spec = statefulSet.getSpec();

and then checking the condition

spec.getReplicas.intValue != status.getReadyReplicas.intValue

However this condition seems to be meeting even when the pods are not Ready!

-- frictionlesspulley
fabric8
kubernetes

1 Answer

5/30/2019

As someone said in the comments, the client API is asynchronous by nature. This means that you should think differently from the procedural way to check the status of an action. As you can see from the documentation https://github.com/fabric8io/kubernetes-client#following-events the client allows you to define a watcher, where you can specify in the anonymous class all the actions to be performed when the desired event/status happens.

-- Antonio Matarrese
Source: StackOverflow