Skip to content

Commit 53680a5

Browse files
Merge pull request #654 from openshift-cherrypick-robot/cherry-pick-648-to-release-4.15
[release-4.15] OCPBUGS-54868: Handle `openshift-host-network` namespace as special when it modifies
2 parents e38935d + dd29c4c commit 53680a5

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

pkg/network/node/networkpolicy.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -603,16 +603,9 @@ func (np *networkPolicyPlugin) selectNamespacesInternal(selector labels.Selector
603603
match := np.nsMatchCache[cacheKey]
604604
if match == nil {
605605
match = &npCacheEntry{selector: selector, matches: make(map[string]uint32)}
606-
for vnid, npns := range np.namespaces {
606+
for _, npns := range np.namespaces {
607607
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()
616609
}
617610
}
618611
np.nsMatchCache[cacheKey] = match
@@ -623,7 +616,7 @@ func (np *networkPolicyPlugin) selectNamespacesInternal(selector labels.Selector
623616
func (np *networkPolicyPlugin) updateMatchCache(npns *npNamespace) {
624617
for _, match := range np.nsMatchCache {
625618
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()
627620
} else {
628621
delete(match.matches, npns.name)
629622
}
@@ -1171,3 +1164,13 @@ func (np *networkPolicyPlugin) refreshPodNetworkPolicies(pod *corev1.Pod) bool {
11711164
func getPodFullName(pod *corev1.Pod) string {
11721165
return fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)
11731166
}
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

Comments
 (0)