Fix: re-instantiate the k8s watcher on receiving onclose event
Change-Id: Id7c1fa3124e3cfaccad4dae5c993d2a2f76d964f
(cherry picked from commit 0201a02b937b6574d4cd916163b6256934aa87e8)
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
index bae08bc..32bed58 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
@@ -138,6 +138,18 @@
log.info("Stopped");
}
+ private void instantiateWatcher() {
+ KubernetesClient client = k8sClient(configService);
+
+ if (client != null) {
+ try {
+ client.customResource(nadCrdCxt).watch(watcher);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
private class InternalKubevirtApiConfigListener implements KubevirtApiConfigListener {
private boolean isRelevantHelper() {
@@ -164,15 +176,7 @@
return;
}
- KubernetesClient client = k8sClient(configService);
-
- if (client != null) {
- try {
- client.customResource(nadCrdCxt).watch(watcher);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ instantiateWatcher();
}
}
@@ -201,7 +205,12 @@
@Override
public void onClose(WatcherException e) {
- log.warn("Network-attachment-definition watcher OnClose", e);
+ // due to the bugs in fabric8, the watcher might be closed,
+ // we will re-instantiate the watcher in this case
+ // FIXME: https://github.com/fabric8io/kubernetes-client/issues/2135
+ log.warn("Network-attachment-definition watcher OnClose, re-instantiate the watcher...");
+
+ instantiateWatcher();
}
private void processAddition(String resource) {