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

Fix: failed get correct asgs when use multiple --node-group-auto-disco… #7009

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions cluster-autoscaler/cloudprovider/aws/auto_scaling_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,10 @@ func (m *asgCache) isPlaceholderInstance(instance *AwsInstanceRef) bool {

// Fetch automatically discovered ASGs. These ASGs should be unregistered if
// they no longer exist in AWS.
func (m *asgCache) buildAsgTags() map[string]string {
groupTags := map[string]string{}
func (m *asgCache) buildAsgTags() []map[string]string {
groupTags := []map[string]string{}
for _, spec := range m.asgAutoDiscoverySpecs {
for k, v := range spec.Tags {
groupTags[k] = v
}
groupTags = append(groupTags, spec.Tags)
}

return groupTags
Expand Down Expand Up @@ -433,9 +431,13 @@ func (m *asgCache) regenerate() error {

refreshTags := m.buildAsgTags()
klog.V(4).Infof("Regenerating instance to ASG map for ASG tags: %v", refreshTags)
taggedGroups, err := m.awsService.getAutoscalingGroupsByTags(refreshTags)
if err != nil {
return err
taggedGroups := []*autoscaling.Group{}
for _, tags := range refreshTags {
groups, err := m.awsService.getAutoscalingGroupsByTags(tags)
if err != nil {
return err
}
taggedGroups = append(taggedGroups, groups...)
}

groups := append(namedGroups, taggedGroups...)
Expand Down
48 changes: 48 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/auto_scaling_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws/aws-sdk-go/aws"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws/aws-sdk-go/service/autoscaling"
)
Expand All @@ -45,6 +46,53 @@ func TestBuildAsg(t *testing.T) {
assert.Error(t, err)
}

func TestBuildAsgTags(t *testing.T) {

cases := []struct {
name string
specs []string
want []map[string]string
wantErr bool
}{
{
name: "MultiSpecs",
specs: []string{
"asg:tag=tag,anothertag",
"asg:tag=cooltag,anothertag",
"asg:tag=label=value,anothertag",
"asg:tag=my:label=value,my:otherlabel=othervalue",
},
want: []map[string]string{
{"tag": "", "anothertag": ""},
{"cooltag": "", "anothertag": ""},
{"label": "value", "anothertag": ""},
{"my:label": "value", "my:otherlabel": "othervalue"},
},
},
{
name: "SingleSpec",
specs: []string{
"asg:tag=mylabel=value,myotherlabel=othervalue",
},
want: []map[string]string{
{"mylabel": "value", "myotherlabel": "othervalue"},
},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
do := cloudprovider.NodeGroupDiscoveryOptions{NodeGroupAutoDiscoverySpecs: tc.specs}
specs, _ := parseASGAutoDiscoverySpecs(do)
asgCache := &asgCache{
asgAutoDiscoverySpecs: specs,
}
got := asgCache.buildAsgTags()
assert.True(t, assert.ObjectsAreEqualValues(tc.want, got), "\ngot: %#v\nwant: %#v", got, tc.want)
})
}
}

func validateAsg(t *testing.T, asg *asg, name string, minSize int, maxSize int) {
assert.Equal(t, name, asg.Name)
assert.Equal(t, minSize, asg.minSize)
Expand Down
Loading