Fix: only handle k8s related device events at k8s-networking app
Change-Id: If5df8eed38b9a0d5653d0ba178170f42199ed3f7
diff --git a/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sSwitchingHostProvider.java b/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sSwitchingHostProvider.java
index c8888ee..85f64bf 100644
--- a/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sSwitchingHostProvider.java
+++ b/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sSwitchingHostProvider.java
@@ -26,6 +26,7 @@
import org.onosproject.k8snetworking.api.K8sNetworkEvent;
import org.onosproject.k8snetworking.api.K8sNetworkListener;
import org.onosproject.k8snetworking.api.K8sPort;
+import org.onosproject.k8snode.api.K8sHostService;
import org.onosproject.k8snode.api.K8sNode;
import org.onosproject.k8snode.api.K8sNodeEvent;
import org.onosproject.k8snode.api.K8sNodeListener;
@@ -34,6 +35,7 @@
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.net.HostLocation;
@@ -71,6 +73,7 @@
import static org.onosproject.k8snetworking.api.Constants.GRE;
import static org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID;
import static org.onosproject.k8snetworking.api.Constants.VXLAN;
+import static org.onosproject.k8snetworking.util.K8sNetworkingUtil.allK8sDevices;
import static org.onosproject.k8snetworking.util.K8sNetworkingUtil.existingContainerPortByMac;
import static org.onosproject.k8snetworking.util.K8sNetworkingUtil.existingContainerPortByName;
import static org.onosproject.k8snetworking.util.K8sNetworkingUtil.isContainer;
@@ -110,6 +113,9 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected K8sNodeService k8sNodeService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected K8sHostService k8sHostService;
+
private HostProviderService hostProviderService;
private final ExecutorService executor = Executors.newSingleThreadExecutor(
@@ -330,8 +336,10 @@
}
String portName = port.annotations().value(PORT_NAME);
+ DeviceId deviceId = event.subject().id();
- return !Strings.isNullOrEmpty(portName) && isContainer(portName);
+ return !Strings.isNullOrEmpty(portName) && isContainer(portName) &&
+ allK8sDevices(k8sNodeService, k8sHostService).contains(deviceId);
}
private boolean isRelevantHelper(DeviceEvent event) {