@@ -603,16 +603,9 @@ func (np *networkPolicyPlugin) selectNamespacesInternal(selector labels.Selector
603
603
match := np .nsMatchCache [cacheKey ]
604
604
if match == nil {
605
605
match = & npCacheEntry {selector : selector , matches : make (map [string ]uint32 )}
606
- for vnid , npns := range np .namespaces {
606
+ for _ , npns := range np .namespaces {
607
607
if npns .gotNamespace && selector .Matches (labels .Set (npns .labels )) {
608
- // handle host network namespace as special and classify it as vnid 0 for
609
- // network policy purposes, so it can ride upon the handling of default
610
- // namespace for host network traffic.
611
- if npns .name == HostNetworkNamespace {
612
- match .matches [npns .name ] = 0
613
- } else {
614
- match .matches [npns .name ] = vnid
615
- }
608
+ match .matches [npns .name ] = npns .GetMatchVNID ()
616
609
}
617
610
}
618
611
np .nsMatchCache [cacheKey ] = match
@@ -623,7 +616,7 @@ func (np *networkPolicyPlugin) selectNamespacesInternal(selector labels.Selector
623
616
func (np * networkPolicyPlugin ) updateMatchCache (npns * npNamespace ) {
624
617
for _ , match := range np .nsMatchCache {
625
618
if npns .gotNamespace && npns .gotNetNamespace && match .selector .Matches (labels .Set (npns .labels )) {
626
- match .matches [npns .name ] = npns .vnid
619
+ match .matches [npns .name ] = npns .GetMatchVNID ()
627
620
} else {
628
621
delete (match .matches , npns .name )
629
622
}
@@ -1171,3 +1164,13 @@ func (np *networkPolicyPlugin) refreshPodNetworkPolicies(pod *corev1.Pod) bool {
1171
1164
func getPodFullName (pod * corev1.Pod ) string {
1172
1165
return fmt .Sprintf ("%s/%s" , pod .Namespace , pod .Name )
1173
1166
}
1167
+
1168
+ // handle host network namespace as special and classify it as vnid 0 for
1169
+ // network policy purposes, so it can ride upon the handling of default
1170
+ // namespace for host network traffic.
1171
+ func (npns * npNamespace ) GetMatchVNID () uint32 {
1172
+ if npns .name == HostNetworkNamespace {
1173
+ return 0
1174
+ }
1175
+ return npns .vnid
1176
+ }
0 commit comments