@@ -35,12 +35,32 @@ import (
3535 utils "k8s.io/autoscaler/cluster-autoscaler/utils/test"
3636)
3737
38+ type mockTemplateNodeInfoRegistry struct {
39+ nodeInfos map [string ]* framework.NodeInfo
40+ }
41+
42+ func newMockTemplateNodeInfoRegistry (nodeInfos map [string ]* framework.NodeInfo ) * mockTemplateNodeInfoRegistry {
43+ return & mockTemplateNodeInfoRegistry {
44+ nodeInfos : nodeInfos ,
45+ }
46+ }
47+
48+ func (m * mockTemplateNodeInfoRegistry ) GetNodeInfo (id string ) (* framework.NodeInfo , bool ) {
49+ nodeInfo , found := m .nodeInfos [id ]
50+ return nodeInfo , found
51+ }
52+
53+ func (m * mockTemplateNodeInfoRegistry ) GetNodeInfos () map [string ]* framework.NodeInfo {
54+ return m .nodeInfos
55+ }
56+
3857func TestFilterOutNodesWithUnreadyDRAResources (t * testing.T ) {
3958 testCases := map [string ]struct {
4059 nodeGroupsAllNodes map [string ][]* apiv1.Node
4160 nodeGroupsTemplatesSlices map [string ][]* resourceapi.ResourceSlice
4261 nodesSlices map [string ][]* resourceapi.ResourceSlice
4362 expectedNodesReadiness map [string ]bool
63+ registryNodeInfos map [string ]* framework.NodeInfo
4464 }{
4565 "1 DRA node group all totally ready" : {
4666 nodeGroupsAllNodes : map [string ][]* apiv1.Node {
@@ -306,6 +326,29 @@ func TestFilterOutNodesWithUnreadyDRAResources(t *testing.T) {
306326 "node_7" : true ,
307327 },
308328 },
329+ "Custom DRA driver retrieved via cached template node info" : {
330+ nodeGroupsAllNodes : map [string ][]* apiv1.Node {
331+ "ng1" : {
332+ buildTestNode ("node_1" , true ),
333+ buildTestNode ("node_2" , true ),
334+ },
335+ },
336+ nodeGroupsTemplatesSlices : map [string ][]* resourceapi.ResourceSlice {},
337+ registryNodeInfos : map [string ]* framework.NodeInfo {
338+ "ng1" : framework .NewNodeInfo (
339+ buildTestNode ("ng1_template" , true ),
340+ createNodeResourceSlices ("ng1_template" , []int {1 }),
341+ ),
342+ },
343+ nodesSlices : map [string ][]* resourceapi.ResourceSlice {
344+ "node_1" : createNodeResourceSlices ("node_1" , []int {1 }),
345+ "node_2" : {},
346+ },
347+ expectedNodesReadiness : map [string ]bool {
348+ "node_1" : true ,
349+ "node_2" : false ,
350+ },
351+ },
309352 }
310353
311354 for tcName , tc := range testCases {
@@ -336,7 +379,11 @@ func TestFilterOutNodesWithUnreadyDRAResources(t *testing.T) {
336379 clusterSnapshotStore .SetClusterState ([]* apiv1.Node {}, []* apiv1.Pod {}, draSnapshot )
337380 clusterSnapshot , _ , _ := testsnapshot .NewCustomTestSnapshotAndHandle (clusterSnapshotStore )
338381
339- autoscalingCtx := & ca_context.AutoscalingContext {CloudProvider : provider , ClusterSnapshot : clusterSnapshot }
382+ autoscalingCtx := & ca_context.AutoscalingContext {
383+ CloudProvider : provider ,
384+ ClusterSnapshot : clusterSnapshot ,
385+ TemplateNodeInfoRegistry : newMockTemplateNodeInfoRegistry (tc .registryNodeInfos ),
386+ }
340387 processor := DraCustomResourcesProcessor {}
341388 newAllNodes , newReadyNodes := processor .FilterOutNodesWithUnreadyResources (autoscalingCtx , initialAllNodes , initialReadyNodes , draSnapshot )
342389
0 commit comments