From 7d7fc2d9892aaaee739256194e780d58c2b4e7a4 Mon Sep 17 00:00:00 2001 From: carlory Date: Thu, 10 Apr 2025 17:58:05 +0800 Subject: [PATCH] Fix flaky test: Metrics should grab all metrics from kubelet /metrics/resource endpoint Signed-off-by: carlory --- test/e2e/framework/node/helper.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/e2e/framework/node/helper.go b/test/e2e/framework/node/helper.go index 604404bf741..012d9712775 100644 --- a/test/e2e/framework/node/helper.go +++ b/test/e2e/framework/node/helper.go @@ -188,10 +188,15 @@ func AddExtendedResource(ctx context.Context, clientSet clientset.Interface, nod extendedResourceList := v1.ResourceList{ extendedResource: extendedResourceQuantity, } - patchPayload, err := json.Marshal(v1.Node{ - Status: v1.NodeStatus{ - Capacity: extendedResourceList, - Allocatable: extendedResourceList, + + // This is a workaround for the fact that we shouldn't marshal a Node struct to JSON + // because it wipes out some fields from node status like the daemonEndpoints and + // nodeInfo which should not be changed at this time. We need to use a map instead. + // See https://github.com/kubernetes/kubernetes/issues/131229 + patchPayload, err := json.Marshal(map[string]any{ + "status": map[string]any{ + "capacity": extendedResourceList, + "allocatable": extendedResourceList, }, }) framework.ExpectNoError(err, "Failed to marshal node JSON")