private Watch doWatchService(String resourceVersion) {
        final Watcher<Service> watcher = new Watcher<Service>() {
            @Override
            public void eventReceived(Action action, Service service0) {
                if (closed) {
                    return;
                }

                numServiceFailures = 0;
                switch (action) {
                    case ADDED:
                    case MODIFIED:
                        if (!service0.getMetadata().getResourceVersion().equals(resourceVersion)) {
                            // Rebuild all resources if the service has been updated.
                            scheduleRestart(0);
                        }
                        break;
                    case DELETED:
                        logger.warn("[{}/{}] service is deleted.", namespace, serviceName);
                        // This situation should not occur in production.
                        break;
                    case ERROR:
                    case BOOKMARK:
                        // Do nothing.
                        break;
                }
            }

            @Override
            public void onClose(WatcherException cause) {
                // Note: As per the JavaDoc of Watcher.onClose(), the method should not be implemented in a
                //       blocking way.
                if (closed) {
                    return;
                }
                logger.warn("[{}/{}] Service watcher is closed.", namespace, serviceName, cause);

                // Immediately retry on the first failure.
                scheduleRestartWithBackoff(++numServiceFailures);
            }

            @Override
            public void onClose() {
                logger.info("[{}/{}] Service watcher is closed gracefully.", namespace, serviceName);
            }
        };

        final Service service = this.service;
        assert service != null;
        if (namespace == null) {
            return client.services().withName(serviceName).withResourceVersion(resourceVersion).watch(watcher);
        } else {
            return client.services().inNamespace(namespace).withName(serviceName)
                         .withResourceVersion(resourceVersion).watch(watcher);
        }
    }
Watches the service. {@link Watcher} will retry automatically on failures by {@link KubernetesClient}.
kubernetes/src/main/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointGroup.java