From 7f6a0b14602dbefdfb387bbea6c0b26e39298a76 Mon Sep 17 00:00:00 2001 From: Justin Miron Date: Thu, 3 Oct 2024 14:33:02 -0500 Subject: [PATCH 1/2] Add metrics-server annotation for kwok-provider managed nodes In order for kwok to correctly simulate metrics usage the following annotation must be set on the nodes: ``` metrics.k8s.io/resource-metrics-path: /metrics/nodes//metrics/resource ``` See https://github.com/kubernetes-sigs/metrics-server/pull/1253 for the metrics-server feature and https://kwok.sigs.k8s.io/docs/user/resource-usage-configuration/ for the KWOK documentation on ResourceUsage. This only used if: - kwok is configured to simulate resource usage of pods. - the cluster is running metrics-server version >= 0.7.0, Otherwise adding this annotation is a noop. --- cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups.go b/cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups.go index cd94a291b797..b92f010f695f 100644 --- a/cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups.go +++ b/cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups.go @@ -76,6 +76,10 @@ func (nodeGroup *NodeGroup) IncreaseSize(delta int) error { for i := 0; i < delta; i++ { node := schedNode.Node() node.Name = fmt.Sprintf("%s-%s", nodeGroup.name, rand.String(5)) + if node.Annotations == nil { + node.Annotations = map[string]string{} + } + node.Annotations["metrics.k8s.io/resource-metrics-path"] = fmt.Sprintf("/metrics/nodes/%s/metrics/resource", node.Name) node.Spec.ProviderID = getProviderID(node.Name) _, err := nodeGroup.kubeClient.CoreV1().Nodes().Create(context.Background(), node, v1.CreateOptions{}) if err != nil { From e26ef60838cd213290ade21bf58fd7bd6f8ba501 Mon Sep 17 00:00:00 2001 From: Justin Miron Date: Tue, 15 Oct 2024 10:08:06 -0500 Subject: [PATCH 2/2] test annotation added to kwok nodes --- cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups_test.go b/cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups_test.go index 5604f1bac6a7..0ec9751e7f4a 100644 --- a/cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups_test.go +++ b/cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups_test.go @@ -71,6 +71,7 @@ func TestIncreaseSize(t *testing.T) { for _, n := range nodes { assert.Contains(t, n.Spec.ProviderID, "kwok") assert.Contains(t, n.GetName(), ng.name) + assert.Contains(t, n.Annotations["metrics.k8s.io/resource-metrics-path"], fmt.Sprintf("/metrics/nodes/%s/metrics/resource", n.GetName())) } // delta is negative