pkg/namespaces: fix NetworkMode IsNS and IsUserDefined

NetworkMode.IsNS matched any value starting with "ns" (e.g. a network named "nsproxy"), unlike UsernsMode.IsNS which requires the "ns:" prefix; require it. IsUserDefined also did not exclude pod, so a pod network was reported as user-defined; exclude it.

Signed-off-by: ROKUMATE <rohitkumawat0110@gmail.com>
This commit is contained in:
ROKUMATE
2026-06-25 03:21:38 +05:30
parent f6afcfaf26
commit a535016f97

View File

@@ -208,7 +208,7 @@ func (n NetworkMode) IsPasta() bool {
// IsNS indicates a network namespace passed in by path (ns:<path>)
func (n NetworkMode) IsNS() bool {
return strings.HasPrefix(string(n), nsType)
return strings.HasPrefix(string(n), nsType+":")
}
// NS gets the path associated with a ns:<path> network ns
@@ -224,5 +224,5 @@ func (n NetworkMode) IsPod() bool {
// IsUserDefined indicates user-created network
func (n NetworkMode) IsUserDefined() bool {
return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer() && !n.IsPasta() && !n.IsNS()
return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer() && !n.IsPasta() && !n.IsNS() && !n.IsPod()
}