Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error if aws fail to find nodegroup for node #2247

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return an error here, but this method gets called looking for Kubernetes nodes that aren't part of a discovered ASG (in my case, my master machines are part of an ASG, but not an ASG that the cluster autoscaler discovers or touches).

In core.getNodeInfosForGroups, we call on this method, and any errors that come back out now cause that function to fail earlier than it used to. It was written to accommodate the nil return here, without an accompanying error.

See #2345 for what may be a consequence of this change (with initial commentary from @losipiuk).

}

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