diff --git a/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sNetworkPolicyHandler.java b/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sNetworkPolicyHandler.java
index ce31f04..1044e39 100644
--- a/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sNetworkPolicyHandler.java
+++ b/apps/k8s-networking/app/src/main/java/org/onosproject/k8snetworking/impl/K8sNetworkPolicyHandler.java
@@ -348,30 +348,7 @@
                 }
 
                 // POD selector
-                Set<Pod> pods = Sets.newConcurrentHashSet();
-                if (peer.getPodSelector() != null) {
-                    Map<String, String> podLabels = peer.getPodSelector().getMatchLabels();
-                    List<LabelSelectorRequirement> matchExps = peer.getPodSelector().getMatchExpressions();
-
-                    if (podLabels == null && matchExps.size() == 0) {
-                        k8sPodService.pods().stream()
-                                .filter(pod -> pod.getMetadata().getNamespace().equals(
-                                        policy.getMetadata().getNamespace()))
-                                .forEach(pods::add);
-                    } else {
-                        k8sPodService.pods().stream()
-                                .filter(pod -> pod.getMetadata().getNamespace().equals(
-                                        policy.getMetadata().getNamespace()))
-                                .forEach(pod -> {
-                                    pod.getMetadata().getLabels().forEach((k, v) -> {
-                                        if (podLabels != null && podLabels.get(k) != null &&
-                                                podLabels.get(k).equals(v)) {
-                                            pods.add(pod);
-                                        }
-                                    });
-                                });
-                    }
-                }
+                Set<Pod> pods = podsFromPolicyPeer(peer, policy.getMetadata().getNamespace());
 
                 pods.forEach(pod -> {
                     white.compute(shiftIpDomain(pod.getStatus().getPodIP(),
@@ -429,33 +406,8 @@
                     }
                 }
 
-                Set<Pod> pods = Sets.newConcurrentHashSet();
-
                 // POD selector
-                if (peer.getPodSelector() != null) {
-                    Map<String, String> podLabels = peer.getPodSelector().getMatchLabels();
-
-                    List<LabelSelectorRequirement> matchExps = peer.getPodSelector().getMatchExpressions();
-
-                    if (podLabels == null && matchExps.size() == 0) {
-                        k8sPodService.pods().stream()
-                                .filter(pod -> pod.getMetadata().getNamespace().equals(
-                                        policy.getMetadata().getNamespace()))
-                                .forEach(pods::add);
-                    } else {
-                        k8sPodService.pods().stream()
-                                .filter(pod -> pod.getMetadata().getNamespace().equals(
-                                        policy.getMetadata().getNamespace()))
-                                .forEach(pod -> {
-                                    pod.getMetadata().getLabels().forEach((k, v) -> {
-                                        if (podLabels != null && podLabels.get(k) != null &&
-                                                podLabels.get(k).equals(v)) {
-                                            pods.add(pod);
-                                        }
-                                    });
-                                });
-                    }
-                }
+                Set<Pod> pods = podsFromPolicyPeer(peer, policy.getMetadata().getNamespace());
 
                 pods.forEach(pod -> {
                     white.compute(shiftIpDomain(pod.getStatus().getPodIP(),
@@ -490,6 +442,34 @@
         setBlackToRouteRules(true);
     }
 
+    private Set<Pod> podsFromPolicyPeer(NetworkPolicyPeer peer, String namespace) {
+        Set<Pod> pods = Sets.newConcurrentHashSet();
+        if (peer.getPodSelector() != null) {
+            Map<String, String> podLabels = peer.getPodSelector().getMatchLabels();
+            List<LabelSelectorRequirement> matchExps = peer.getPodSelector().getMatchExpressions();
+
+            if (podLabels == null && matchExps.size() == 0) {
+                k8sPodService.pods().stream()
+                        .filter(pod -> pod.getMetadata().getNamespace().equals(
+                                namespace))
+                        .forEach(pods::add);
+            } else {
+                k8sPodService.pods().stream()
+                        .filter(pod -> pod.getMetadata().getNamespace().equals(
+                                namespace))
+                        .forEach(pod -> {
+                            pod.getMetadata().getLabels().forEach((k, v) -> {
+                                if (podLabels != null && podLabels.get(k) != null &&
+                                        podLabels.get(k).equals(v)) {
+                                    pods.add(pod);
+                                }
+                            });
+                        });
+            }
+        }
+        return pods;
+    }
+
     private void setAllowRulesByPod(Pod pod, boolean install) {
         Map<String, Map<String, List<NetworkPolicyPort>>>
                 white = Maps.newConcurrentMap();
