diff --git a/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go b/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go index b6ee7ac6ac59..f524c537b438 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go @@ -108,7 +108,7 @@ func (aws *awsCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.N asg := aws.awsManager.GetAsgForInstance(*ref) if asg == nil { - return nil, fmt.Errorf("cannot find ASG for node %v", ref.Name) + return nil, nil } return &AwsNodeGroup{ diff --git a/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider_test.go b/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider_test.go index 02dbacec2838..17aa8e85457e 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider_test.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider_test.go @@ -241,36 +241,33 @@ func TestNodeGroupForNode(t *testing.T) { assert.Equal(t, []cloudprovider.Instance{{Id: "aws:///us-east-1a/test-instance-id"}}, nodes) service.AssertNumberOfCalls(t, "DescribeAutoScalingGroupsPages", 1) -} -func TestNodeGroupForNodeWithNoProviderId(t *testing.T) { - node := &apiv1.Node{ + // test node in cluster that is not in a group managed by cluster autoscaler + nodeNotInGroup := &apiv1.Node{ Spec: apiv1.NodeSpec{ - ProviderID: "", + ProviderID: "aws:///us-east-1a/test-instance-id-not-in-group", }, } - service := &AutoScalingMock{} - provider := testProvider(t, newTestAwsManagerWithAsgs(t, service, []string{"1:5:test-asg"})) - group, err := provider.NodeGroupForNode(node) + + group, err = provider.NodeGroupForNode(nodeNotInGroup) assert.NoError(t, err) - assert.Equal(t, group, nil) + assert.Nil(t, group) + service.AssertNumberOfCalls(t, "DescribeAutoScalingGroupsPages", 1) } -func TestNodeGroupForNodeWithOutNodeGroup(t *testing.T) { - // test node in cluster that is not in a group managed by cluster autoscaler +func TestNodeGroupForNodeWithNoProviderId(t *testing.T) { node := &apiv1.Node{ Spec: apiv1.NodeSpec{ - ProviderID: "aws:///us-east-1a/test-instance-id", + ProviderID: "", }, } service := &AutoScalingMock{} provider := testProvider(t, newTestAwsManagerWithAsgs(t, service, []string{"1:5:test-asg"})) group, err := provider.NodeGroupForNode(node) - assert.Error(t, err) + assert.NoError(t, err) assert.Equal(t, group, nil) - service.AssertNotCalled(t, "DescribeAutoScalingGroupsPages") } func TestAwsRefFromProviderId(t *testing.T) {