Skip to content

Commit d822c90

Browse files
EricMountaink8s-infra-cherrypick-robot
authored andcommitted
CRI: Stable sort for RuntimeHandlers
The runtimeHandlers list in the response to `crictl info` has unstable ordering since commit 97eb1cd (underlying switch from list to map) that was shipped in v2.1.0. On Kubernetes nodes this causes the kubelet to update node status subresources every time the order of runtime handlers changes in the status response from containerd. The lieklihood increases with the number of runtime handlers present on nodes. In some clusters this leads to every single node sending a status update every few seconds leading to excessive Kube API server load. This change enforces stable ordering on runtime handler names. Signed-off-by: Eric Mountain <[email protected]>
1 parent a2fd706 commit d822c90

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

internal/cri/server/status.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"maps"
2424
goruntime "runtime"
2525
"slices"
26+
"sort"
2627

2728
"github.com/containerd/containerd/api/services/introspection/v1"
2829
"github.com/containerd/log"
@@ -59,9 +60,15 @@ func (c *criService) Status(ctx context.Context, r *runtime.StatusRequest) (*run
5960
runtimeCondition,
6061
networkCondition,
6162
}},
62-
RuntimeHandlers: slices.Collect(maps.Values(c.runtimeHandlers)),
63-
Features: c.runtimeFeatures,
63+
Features: c.runtimeFeatures,
6464
}
65+
66+
// Ensure stable ordering of runtime handlers in response
67+
resp.RuntimeHandlers = slices.Collect(maps.Values(c.runtimeHandlers))
68+
sort.SliceStable(resp.RuntimeHandlers, func(i, j int) bool {
69+
return resp.RuntimeHandlers[i].Name < resp.RuntimeHandlers[j].Name
70+
})
71+
6572
if r.Verbose {
6673
configByt, err := json.Marshal(c.config)
6774
if err != nil {

0 commit comments

Comments
 (0)