Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-44674: Handle openshift-host-network namespace as special when it modifies #648

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions pkg/network/node/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,16 +616,9 @@ func (np *networkPolicyPlugin) selectNamespacesInternal(selector labels.Selector
match := np.nsMatchCache[cacheKey]
if match == nil {
match = &npCacheEntry{selector: selector, matches: make(map[string]uint32)}
for vnid, npns := range np.namespaces {
for _, npns := range np.namespaces {
if npns.gotNamespace && selector.Matches(labels.Set(npns.labels)) {
// handle host network namespace as special and classify it as vnid 0 for
// network policy purposes, so it can ride upon the handling of default
// namespace for host network traffic.
if npns.name == HostNetworkNamespace {
match.matches[npns.name] = 0
} else {
match.matches[npns.name] = vnid
}
match.matches[npns.name] = npns.GetMatchVNID()
}
}
np.nsMatchCache[cacheKey] = match
Expand All @@ -636,7 +629,7 @@ func (np *networkPolicyPlugin) selectNamespacesInternal(selector labels.Selector
func (np *networkPolicyPlugin) updateMatchCache(npns *npNamespace) {
for _, match := range np.nsMatchCache {
if npns.gotNamespace && npns.gotNetNamespace && match.selector.Matches(labels.Set(npns.labels)) {
match.matches[npns.name] = npns.vnid
match.matches[npns.name] = npns.GetMatchVNID()
} else {
delete(match.matches, npns.name)
}
Expand Down Expand Up @@ -1190,3 +1183,13 @@ func (np *networkPolicyPlugin) refreshPodNetworkPolicies(pod *corev1.Pod) bool {
func getPodFullName(pod *corev1.Pod) string {
return fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)
}

// handle host network namespace as special and classify it as vnid 0 for
// network policy purposes, so it can ride upon the handling of default
// namespace for host network traffic.
func (npns *npNamespace) GetMatchVNID() uint32 {
if npns.name == HostNetworkNamespace {
return 0
}
return npns.vnid
}