<p>What does the Action ADD in fabric8 watch API mean? My initial understanding of it is to add a resource, but I tested it and a bunch of ADD Actions were triggered. </p>

shadowsocks
<p>Yes, Fabric8 Kubernetes Client's <code>WatchEvent</code> basically maps to Kubernetes <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/watch/json/types.go#L32" rel="nofollow noreferrer"><code>pkg/watch/json</code></a>. So <code>EventType</code> in it is basically a <code>String</code> value which is sent by Kubernetes API server as a response and you need to handle what you need to do on the type of event. It can have these values: <code>ADDED</code>, <code>DELETED</code>, <code>MODIFIED</code>, <code>BOOKMARK</code>, <code>ERROR</code>. When you start the watch without any <code>resourceVersion</code> as a parameter, it would just start with resource version set to <code>0</code>. It starts watch from the beginning and you see <code>ADD</code> actions being triggered for the resources which are already in the cluster. I think you must have seen this behavior when you use <code>kubectl</code> as well:</p>

<pre><code>~/go/src/github.com/fabric8io/kubernetes-client/kubernetes-model/kubernetes-model-core : $ kubectl get pods -w
NAME                                           READY   STATUS    RESTARTS   AGE
&lt;These are pre existing resources listed since start of watch&gt;
nginx-deployment-54f57cf6bf-4swvr              1/1     Running   1   &lt;        2d5h
nginx-deployment-54f57cf6bf-4swvr-clonem6sg6   1/1     Running   1          2d5h
testpod                                        1/1     Running   1          2d5h
testpod-cloneb5fkz                             1/1     Running   1          2d5h

&lt;You should be able to see events after you do some changes&gt;
testpod                                        1/1     Running   1          2d5h

</code></pre>

<p>If you go ahead and create some more resources, you should be able to see more <code>ADDED</code> actions being triggered. On modifying, you should be seeing <code>MODIFIED</code> events as well. These are sent by Kubernetes APIServer and Fabric8 Kubernetes Client just deserializes them into Java objects.</p>

<p>So, while watching I would suggest you to handle all the cases depending upon your situation inside the <code>eventReceived()</code> call like this:</p>

<pre><code>// Latch for Watch termination
final CountDownLatch isWatchClosed = new CountDownLatch(1);
try (KubernetesClient client = new DefaultKubernetesClient()) {
    client.pods().inNamespace(namespace).watch(new Watcher&lt;Pod&gt;() {
        @Override
        public void eventReceived(Action action, Pod pod) {
            logger.log(Level.INFO, action.name() + " " + pod.getMetadata().getName());
            switch (action.name()) {
                case "ADDED":
                    logger.log(Level.INFO, pod.getMetadata().getName() + "got added");
                    break;
                case "DELETED":
                    logger.log(Level.INFO, pod.getMetadata().getName() + "got deleted");
                    break;
                case "MODIFIED":
                    logger.log(Level.INFO, pod.getMetadata().getName() + "got modified");
                    break;
                default:
                    logger.log(Level.SEVERE, "Unrecognized event: " + action.name());
            }
        }

        @Override
        public void onClose(KubernetesClientException e) {
            logger.log(Level.INFO, "Closed");
            isWatchClosed.countDown();
        }
    });

    // Wait till watch gets closed
    isWatchClosed.await();
} catch (InterruptedException interruptedException) {
    logger.log(Level.INFO, "Thread Interrupted!");
    Thread.currentThread().interrupt();
}
</code></pre>

<p>I hope this clears your understanding of Fabric8's WatchEvent types.</p>
