From b1449fd5102dfd58859c18ce5aae7bbcc980e61d Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 9 Sep 2024 18:25:28 -0700 Subject: [PATCH] libct: use Namespaces.IsPrivate more In these cases, this is exactly what we want to find out. Slightly improves performance and readability. Signed-off-by: Kir Kolyshkin --- libcontainer/configs/validate/rootless.go | 2 +- libcontainer/specconv/spec_linux.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libcontainer/configs/validate/rootless.go b/libcontainer/configs/validate/rootless.go index faceea04c..4507d4495 100644 --- a/libcontainer/configs/validate/rootless.go +++ b/libcontainer/configs/validate/rootless.go @@ -34,7 +34,7 @@ func rootlessEUIDMappings(config *configs.Config) error { return errors.New("rootless container requires user namespaces") } // We only require mappings if we are not joining another userns. - if path := config.Namespaces.PathOf(configs.NEWUSER); path == "" { + if config.Namespaces.IsPrivate(configs.NEWUSER) { if len(config.UIDMappings) == 0 { return errors.New("rootless containers requires at least one UID mapping") } diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go index ae08a827c..e7c6faae3 100644 --- a/libcontainer/specconv/spec_linux.go +++ b/libcontainer/specconv/spec_linux.go @@ -415,7 +415,7 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) { } config.Namespaces.Add(t, ns.Path) } - if config.Namespaces.Contains(configs.NEWNET) && config.Namespaces.PathOf(configs.NEWNET) == "" { + if config.Namespaces.IsPrivate(configs.NEWNET) { config.Networks = []*configs.Network{ { Type: "loopback", @@ -481,7 +481,7 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) { // Only set it if the container will have its own cgroup // namespace and the cgroupfs will be mounted read/write. // - hasCgroupNS := config.Namespaces.Contains(configs.NEWCGROUP) && config.Namespaces.PathOf(configs.NEWCGROUP) == "" + hasCgroupNS := config.Namespaces.IsPrivate(configs.NEWCGROUP) hasRwCgroupfs := false if hasCgroupNS { for _, m := range config.Mounts {