Skip to content

Commit f5e518e

Browse files
authored
Merge pull request #91 from cloudnativelabs/90-network-policy-ga
Netork policy GA: select all pods in namespace if pod selector is not specified in the network policy spec
2 parents 562008c + 279bc66 commit f5e518e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

app/controllers/network_policy_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,19 @@ func (npc *NetworkPolicyController) getFirewallEnabledPods(nodeIp string) (*map[
595595
podNeedsFirewall := false
596596
for _, policy_obj := range watchers.NetworkPolicyWatcher.List() {
597597
policy, _ := policy_obj.(*networking.NetworkPolicy)
598+
599+
// we are only interested in the network policies in same namespace that of pod
598600
if policy.Namespace != pod.ObjectMeta.Namespace {
599601
continue
600602
}
603+
604+
// An empty podSelector matches all pods in this namespace.
605+
if len(policy.Spec.PodSelector.MatchLabels) == 0 || len(policy.Spec.PodSelector.MatchExpressions) == 0 {
606+
podNeedsFirewall = true
607+
break
608+
}
609+
610+
// if pod matches atleast on network policy labels then pod needs firewall
601611
matchingPods, err := watchers.PodWatcher.ListByNamespaceAndLabels(policy.Namespace,
602612
policy.Spec.PodSelector.MatchLabels)
603613
if err != nil {

0 commit comments

Comments
 (0)