From 6bfd28bc6fbe52f40d6d86ed95382205492aff6e Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 18 Jun 2025 14:39:17 +0200 Subject: [PATCH] pkg/namespaces: remove deadcode These types are not used. Signed-off-by: Paul Holzinger --- pkg/namespaces/namespaces.go | 193 ----------------------------------- 1 file changed, 193 deletions(-) diff --git a/pkg/namespaces/namespaces.go b/pkg/namespaces/namespaces.go index 9449ff464c..9464d9d485 100644 --- a/pkg/namespaces/namespaces.go +++ b/pkg/namespaces/namespaces.go @@ -30,65 +30,6 @@ type KeepIDUserNsOptions struct { MaxSize *uint32 } -// CgroupMode represents cgroup mode in the container. -type CgroupMode string - -// IsHost indicates whether the container uses the host's cgroup. -func (n CgroupMode) IsHost() bool { - return n == hostType -} - -// IsDefaultValue indicates whether the cgroup namespace has the default value. -func (n CgroupMode) IsDefaultValue() bool { - return n == "" || n == defaultType -} - -// IsNS indicates a cgroup namespace passed in by path (ns:) -func (n CgroupMode) IsNS() bool { - return strings.HasPrefix(string(n), nsType) -} - -// NS gets the path associated with a ns: cgroup ns -func (n CgroupMode) NS() string { - _, path, _ := strings.Cut(string(n), ":") - return path -} - -// IsContainer indicates whether the container uses a new cgroup namespace. -func (n CgroupMode) IsContainer() bool { - typ, _, hasColon := strings.Cut(string(n), ":") - return hasColon && typ == containerType -} - -// Container returns the name of the container whose cgroup namespace is going to be used. -func (n CgroupMode) Container() string { - typ, name, hasName := strings.Cut(string(n), ":") - if hasName && typ == containerType { - return name - } - return "" -} - -// IsPrivate indicates whether the container uses the a private cgroup. -func (n CgroupMode) IsPrivate() bool { - return n == privateType -} - -// Valid indicates whether the Cgroup namespace is valid. -func (n CgroupMode) Valid() bool { - parts := strings.Split(string(n), ":") - switch mode := parts[0]; mode { - case "", hostType, privateType, nsType: - case containerType: - if len(parts) != 2 || parts[1] == "" { - return false - } - default: - return false - } - return true -} - // UsernsMode represents userns mode in the container. type UsernsMode string @@ -210,140 +151,6 @@ func (n UsernsMode) Container() string { return "" } -// UTSMode represents the UTS namespace of the container. -type UTSMode string - -// IsPrivate indicates whether the container uses its private UTS namespace. -func (n UTSMode) IsPrivate() bool { - return !(n.IsHost()) -} - -// IsHost indicates whether the container uses the host's UTS namespace. -func (n UTSMode) IsHost() bool { - return n == hostType -} - -// IsContainer indicates whether the container uses a container's UTS namespace. -func (n UTSMode) IsContainer() bool { - typ, _, hasName := strings.Cut(string(n), ":") - return hasName && typ == containerType -} - -// Container returns the name of the container whose uts namespace is going to be used. -func (n UTSMode) Container() string { - typ, name, hasName := strings.Cut(string(n), ":") - if hasName && typ == containerType { - return name - } - return "" -} - -// Valid indicates whether the UTS namespace is valid. -func (n UTSMode) Valid() bool { - parts := strings.Split(string(n), ":") - switch mode := parts[0]; mode { - case "", privateType, hostType: - case containerType: - if len(parts) != 2 || parts[1] == "" { - return false - } - default: - return false - } - return true -} - -// IpcMode represents the container ipc stack. -type IpcMode string - -// IsPrivate indicates whether the container uses its own private ipc namespace which cannot be shared. -func (n IpcMode) IsPrivate() bool { - return n == privateType -} - -// IsHost indicates whether the container shares the host's ipc namespace. -func (n IpcMode) IsHost() bool { - return n == hostType -} - -// IsShareable indicates whether the container uses its own shareable ipc namespace which can be shared. -func (n IpcMode) IsShareable() bool { - return n == shareableType -} - -// IsContainer indicates whether the container uses another container's ipc namespace. -func (n IpcMode) IsContainer() bool { - typ, _, hasName := strings.Cut(string(n), ":") - return hasName && typ == containerType -} - -// IsNone indicates whether container IpcMode is set to "none". -func (n IpcMode) IsNone() bool { - return n == noneType -} - -// IsEmpty indicates whether container IpcMode is empty -func (n IpcMode) IsEmpty() bool { - return n == "" -} - -// Valid indicates whether the ipc mode is valid. -func (n IpcMode) Valid() bool { - return n.IsEmpty() || n.IsNone() || n.IsPrivate() || n.IsHost() || n.IsShareable() || n.IsContainer() -} - -// Container returns the name of the container ipc stack is going to be used. -func (n IpcMode) Container() string { - typ, name, hasName := strings.Cut(string(n), ":") - if hasName && typ == containerType { - return name - } - return "" -} - -// PidMode represents the pid namespace of the container. -type PidMode string - -// IsPrivate indicates whether the container uses its own new pid namespace. -func (n PidMode) IsPrivate() bool { - return !n.IsHost() && !n.IsContainer() -} - -// IsHost indicates whether the container uses the host's pid namespace. -func (n PidMode) IsHost() bool { - return n == hostType -} - -// IsContainer indicates whether the container uses a container's pid namespace. -func (n PidMode) IsContainer() bool { - typ, _, hasName := strings.Cut(string(n), ":") - return hasName && typ == containerType -} - -// Valid indicates whether the pid namespace is valid. -func (n PidMode) Valid() bool { - parts := strings.Split(string(n), ":") - switch mode := parts[0]; mode { - case "", privateType, hostType: - case containerType: - if len(parts) != 2 || parts[1] == "" { - return false - } - default: - return false - } - return true -} - -// Container returns the name of the container whose pid namespace is going to be used. -func (n PidMode) Container() string { - typ, name, hasName := strings.Cut(string(n), ":") - if hasName && typ == containerType { - return name - } - return "" -} - // NetworkMode represents the container network stack. type NetworkMode string