title: correct way to use kubernetes watches
body: <p>I am new to Kubernetes and I am not really sure on how to proceed to implement correctly a watch; especially I am not sure on how to deal with the resourceVersion parameter.</p>
  
  <p>The goal is to watch for new pods with a specific label, and in case of error or disconnection from the cluster being able to restart the watch from the last event occurred.</p>
  
  <p>I am doing something like this:</p>
  
  <pre><code>// after setting up the connection and some parameters
  String lastResourceVersion = null; // at beginning version is unknown
  while (true) {
    try {
      Watch&lt;V1Pod&gt; watcher = Watch.createWatch(
              client,
              api.listNamespacedPodCall(namespace, pretty, fieldSelector, labelSelector, lastResourceVersion, forEver, true, null, null),
              new TypeToken&lt;Watch.Response&lt;V1Pod&gt;&gt;() {}.getType()
      );
      for (Watch.Response&lt;V1Pod&gt; item : watcher) {
        //increment the version
        lastResourceVersion = item.object.getMetadata().getResourceVersion();
        // do some stuff with the pod
      }
    } catch (ApiException apiException) {
      log.error("restarting the watch from "+lastResourceVersion, apiException);
    }
  }
  </code></pre>
  
  <p>Is it correct to use the resourceVersion of a Pod to reinitialize the watch call? Is this number a kind of timestamp for all the events in the cluster, or different api will use different sequences?</p>
  
  <p>Do I need to watch for specific exceptions? eg. in case of the resourceVersion is to old?</p>
  
  <p>thanks</p>