diff --git a/cluster-autoscaler/cloudprovider/test/test_cloud_provider.go b/cluster-autoscaler/cloudprovider/test/test_cloud_provider.go index 190d016b6d..4c13ac52c3 100644 --- a/cluster-autoscaler/cloudprovider/test/test_cloud_provider.go +++ b/cluster-autoscaler/cloudprovider/test/test_cloud_provider.go @@ -99,6 +99,13 @@ func (tcp *TestCloudProvider) NodeGroups() []cloudprovider.NodeGroup { return result } +// GetNodeGroup returns node group with the given name. +func (tcp *TestCloudProvider) GetNodeGroup(name string) cloudprovider.NodeGroup { + tcp.Lock() + defer tcp.Unlock() + return tcp.groups[name] +} + // NodeGroupForNode returns the node group for the given node, nil if the node // should not be processed by cluster autoscaler, or non-nil error if such // occurred. diff --git a/cluster-autoscaler/core/static_autoscaler_test.go b/cluster-autoscaler/core/static_autoscaler_test.go index 21281c7a1c..e54a8aabce 100644 --- a/cluster-autoscaler/core/static_autoscaler_test.go +++ b/cluster-autoscaler/core/static_autoscaler_test.go @@ -153,7 +153,8 @@ func TestStaticAutoscalerRunOnce(t *testing.T) { nil, map[string]*schedulercache.NodeInfo{"ng1": tni}) provider.AddNodeGroup("ng1", 1, 10, 1) provider.AddNode("ng1", n1) - ng1 := reflect.ValueOf(provider.NodeGroups()[0]).Interface().(*testprovider.TestNodeGroup) + ng1 := reflect.ValueOf(provider.GetNodeGroup("ng1")).Interface().(*testprovider.TestNodeGroup) + assert.NotNil(t, ng1) assert.NotNil(t, provider) fakeClient := &fake.Clientset{} @@ -328,7 +329,8 @@ func TestStaticAutoscalerRunOnceWithAutoprovisionedEnabled(t *testing.T) { []string{"TN1", "TN2"}, map[string]*schedulercache.NodeInfo{"TN1": tni1, "TN2": tni2, "ng1": tni3}) provider.AddNodeGroup("ng1", 1, 10, 1) provider.AddAutoprovisionedNodeGroup("autoprovisioned-TN1", 0, 10, 0, "TN1") - autoprovisionedTN1 := reflect.ValueOf(provider.NodeGroups()[1]).Interface().(*testprovider.TestNodeGroup) + autoprovisionedTN1 := reflect.ValueOf(provider.GetNodeGroup("autoprovisioned-TN1")).Interface().(*testprovider.TestNodeGroup) + assert.NotNil(t, autoprovisionedTN1) provider.AddNode("ng1,", n1) assert.NotNil(t, provider) @@ -461,7 +463,8 @@ func TestStaticAutoscalerRunOnceWithALongUnregisteredNode(t *testing.T) { brokenNode := BuildTestNode("broken", 1000, 1000) provider.AddNode("ng1", brokenNode) - ng1 := reflect.ValueOf(provider.NodeGroups()[0]).Interface().(*testprovider.TestNodeGroup) + ng1 := reflect.ValueOf(provider.GetNodeGroup("ng1")).Interface().(*testprovider.TestNodeGroup) + assert.NotNil(t, ng1) assert.NotNil(t, provider) fakeClient := &fake.Clientset{} @@ -600,7 +603,8 @@ func TestStaticAutoscalerRunOncePodsWithPriorities(t *testing.T) { provider.AddNode("ng2", n2) provider.AddNode("ng2", n3) assert.NotNil(t, provider) - ng2 := reflect.ValueOf(provider.NodeGroups()[1]).Interface().(*testprovider.TestNodeGroup) + ng2 := reflect.ValueOf(provider.GetNodeGroup("ng2")).Interface().(*testprovider.TestNodeGroup) + assert.NotNil(t, ng2) fakeClient := &fake.Clientset{} fakeRecorder := kube_record.NewFakeRecorder(5)