From 5f00061251d7d7fd6e241685dff0903ee38a8d4b Mon Sep 17 00:00:00 2001 From: Eric Mountain Date: Fri, 27 Jun 2025 13:42:58 +0200 Subject: [PATCH] CRI: Stable sort for RuntimeHandlers The runtimeHandlers list in the response to `crictl info` has unstable ordering since commit 97eb1cd that uses a map instead of a list. This causes the kubelet to update node status subresources every few seconds leading to excessive API server load. This change enforces stable ordering based on the runtime handler name. --- internal/cri/server/status.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/cri/server/status.go b/internal/cri/server/status.go index a88872445891c..9123a70308fd0 100644 --- a/internal/cri/server/status.go +++ b/internal/cri/server/status.go @@ -23,6 +23,7 @@ import ( "maps" goruntime "runtime" "slices" + "sort" "github.com/containerd/containerd/api/services/introspection/v1" "github.com/containerd/log" @@ -59,9 +60,15 @@ func (c *criService) Status(ctx context.Context, r *runtime.StatusRequest) (*run runtimeCondition, networkCondition, }}, - RuntimeHandlers: slices.Collect(maps.Values(c.runtimeHandlers)), - Features: c.runtimeFeatures, + Features: c.runtimeFeatures, } + + // Get runtime handlers in a stable order + resp.RuntimeHandlers = slices.Collect(maps.Values(c.runtimeHandlers)) + sort.SliceStable(resp.RuntimeHandlers, func(i, j int) bool { + return resp.RuntimeHandlers[i].Name < resp.RuntimeHandlers[j].Name + }) + if r.Verbose { configByt, err := json.Marshal(c.config) if err != nil {