Skip to content

Commit

Permalink
Return error if aws fail to find nodegroup for node
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffwan committed Aug 10, 2019
1 parent 8303a23 commit f65e47a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (aws *awsCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.N
asg := aws.awsManager.GetAsgForInstance(*ref)

if asg == nil {
return nil, nil
return nil, fmt.Errorf("cannot find ASG for node %v", ref.Name)
}

return &AwsNodeGroup{
Expand Down
23 changes: 13 additions & 10 deletions cluster-autoscaler/cloudprovider/aws/aws_cloud_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,33 +241,36 @@ func TestNodeGroupForNode(t *testing.T) {

assert.Equal(t, []cloudprovider.Instance{{Id: "aws:///us-east-1a/test-instance-id"}}, nodes)
service.AssertNumberOfCalls(t, "DescribeAutoScalingGroupsPages", 1)
}

// test node in cluster that is not in a group managed by cluster autoscaler
nodeNotInGroup := &apiv1.Node{
func TestNodeGroupForNodeWithNoProviderId(t *testing.T) {
node := &apiv1.Node{
Spec: apiv1.NodeSpec{
ProviderID: "aws:///us-east-1a/test-instance-id-not-in-group",
ProviderID: "",
},
}

group, err = provider.NodeGroupForNode(nodeNotInGroup)
service := &AutoScalingMock{}
provider := testProvider(t, newTestAwsManagerWithAsgs(t, service, []string{"1:5:test-asg"}))
group, err := provider.NodeGroupForNode(node)

assert.NoError(t, err)
assert.Nil(t, group)
service.AssertNumberOfCalls(t, "DescribeAutoScalingGroupsPages", 1)
assert.Equal(t, group, nil)
}

func TestNodeGroupForNodeWithNoProviderId(t *testing.T) {
func TestNodeGroupForNodeWithOutNodeGroup(t *testing.T) {
// test node in cluster that is not in a group managed by cluster autoscaler
node := &apiv1.Node{
Spec: apiv1.NodeSpec{
ProviderID: "",
ProviderID: "aws:///us-east-1a/test-instance-id",
},
}
service := &AutoScalingMock{}
provider := testProvider(t, newTestAwsManagerWithAsgs(t, service, []string{"1:5:test-asg"}))
group, err := provider.NodeGroupForNode(node)

assert.NoError(t, err)
assert.Error(t, err)
assert.Equal(t, group, nil)
service.AssertNotCalled(t, "DescribeAutoScalingGroupsPages")
}

func TestAwsRefFromProviderId(t *testing.T) {
Expand Down

0 comments on commit f65e47a

Please sign in to comment.