From 370733b7d993414e4a62da48fc2069c470a41e47 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 21 Mar 2025 15:50:15 -0700 Subject: [PATCH 1/2] libct/cap: rm mapKeys, use maps.Keys, slices.Sorted Since we've switched to Go 1.23 we can now use the new functionality of maps and slices packages. Signed-off-by: Kir Kolyshkin --- libcontainer/capabilities/capabilities.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/libcontainer/capabilities/capabilities.go b/libcontainer/capabilities/capabilities.go index 8bddc0007..157d84cd9 100644 --- a/libcontainer/capabilities/capabilities.go +++ b/libcontainer/capabilities/capabilities.go @@ -5,7 +5,8 @@ package capabilities import ( "errors" "fmt" - "sort" + "maps" + "slices" "strings" "sync" "syscall" @@ -67,7 +68,7 @@ func New(capConfig *configs.Capabilities) (*Caps, error) { return nil, err } if len(unknownCaps) > 0 { - logrus.Warn("ignoring unknown or unavailable capabilities: ", mapKeys(unknownCaps)) + logrus.Warn("ignoring unknown or unavailable capabilities: ", slices.Sorted(maps.Keys(unknownCaps))) } return &c, nil } @@ -88,16 +89,6 @@ func capSlice(caps []string, unknownCaps map[string]struct{}) []capability.Cap { return out } -// mapKeys returns the keys of input in sorted order -func mapKeys(input map[string]struct{}) []string { - keys := make([]string, 0, len(input)) - for c := range input { - keys = append(keys, c) - } - sort.Strings(keys) - return keys -} - // Caps holds the capabilities for a container. type Caps struct { pid capability.Capabilities From bc96bc8558aa0dfe8edbb691489a3487003d8112 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 21 Mar 2025 15:50:43 -0700 Subject: [PATCH 2/2] libct/seccomp: use maps and slices pkgs Since we have now switched to Go 1.23, we can use maps and slices pkgs Signed-off-by: Kir Kolyshkin --- libcontainer/seccomp/config.go | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/libcontainer/seccomp/config.go b/libcontainer/seccomp/config.go index 3ca03ed8a..06849c83c 100644 --- a/libcontainer/seccomp/config.go +++ b/libcontainer/seccomp/config.go @@ -2,7 +2,8 @@ package seccomp import ( "fmt" - "sort" + "maps" + "slices" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runtime-spec/specs-go" @@ -25,12 +26,7 @@ var operators = map[string]configs.Operator{ // KnownOperators returns the list of the known operations. // Used by `runc features`. func KnownOperators() []string { - var res []string - for k := range operators { - res = append(res, k) - } - sort.Strings(res) - return res + return slices.Sorted(maps.Keys(operators)) } var actions = map[string]configs.Action{ @@ -48,12 +44,7 @@ var actions = map[string]configs.Action{ // KnownActions returns the list of the known actions. // Used by `runc features`. func KnownActions() []string { - var res []string - for k := range actions { - res = append(res, k) - } - sort.Strings(res) - return res + return slices.Sorted(maps.Keys(actions)) } var archs = map[string]string{ @@ -79,12 +70,7 @@ var archs = map[string]string{ // KnownArchs returns the list of the known archs. // Used by `runc features`. func KnownArchs() []string { - var res []string - for k := range archs { - res = append(res, k) - } - sort.Strings(res) - return res + return slices.Sorted(maps.Keys(archs)) } // ConvertStringToOperator converts a string into a Seccomp comparison operator.