Skip to content

Commit

Permalink
skip host network pods when selecting pods to apply ingress/egress ne…
Browse files Browse the repository at this point in the history
…tpol
  • Loading branch information
murali-reddy authored and aauren committed May 25, 2021
1 parent a042e0e commit e49c255
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/controllers/netpol/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (npc *NetworkPolicyController) newPodEventHandler() cache.ResourceEventHand
func (npc *NetworkPolicyController) OnPodUpdate(obj interface{}) {
pod := obj.(*api.Pod)
if pod.Spec.HostNetwork {
klog.V(2).Info("Ignoring update to hostNetwork pod: %s/%s", pod.Namespace, pod.Name)
klog.V(2).Infof("Ignoring update to hostNetwork pod: %s/%s", pod.Namespace, pod.Name)
return
}
klog.V(2).Infof("Received update to pod: %s/%s", pod.Namespace, pod.Name)
Expand Down Expand Up @@ -226,9 +226,11 @@ func (npc *NetworkPolicyController) getIngressNetworkPolicyEnabledPods(networkPo
for _, obj := range npc.podLister.List() {
pod := obj.(*api.Pod)

if strings.Compare(pod.Status.HostIP, nodeIP) != 0 {
// ignore the pods running on the different node or running in host network
if strings.Compare(pod.Status.HostIP, nodeIP) != 0 || pod.Spec.HostNetwork {
continue
}

for _, policy := range networkPoliciesInfo {
if policy.namespace != pod.ObjectMeta.Namespace {
continue
Expand All @@ -255,7 +257,8 @@ func (npc *NetworkPolicyController) getEgressNetworkPolicyEnabledPods(networkPol
for _, obj := range npc.podLister.List() {
pod := obj.(*api.Pod)

if strings.Compare(pod.Status.HostIP, nodeIP) != 0 {
// ignore the pods running on the different node or running in host network
if strings.Compare(pod.Status.HostIP, nodeIP) != 0 || pod.Spec.HostNetwork {
continue
}
for _, policy := range networkPoliciesInfo {
Expand Down

0 comments on commit e49c255

Please sign in to comment.