Skip to content

Commit

Permalink
Ignore changes reported by subsequent updates
Browse files Browse the repository at this point in the history
Usually this is an "actual.Foo = e.Foo" one-liner but we don't know which LB attached to an ASG is the API ELB so it's a bit more complicated
  • Loading branch information
rifelpet committed Oct 29, 2020
1 parent 7497eda commit ee430a3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elb"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -124,6 +125,37 @@ func (e *AutoscalingGroup) Find(c *fi.Context) (*AutoscalingGroup, error) {
})
}

{
// pkg/model/awsmodel/autoscalinggroup.go doesn't know the LoadBalancerName of the API ELB task that it sets up
// it only knows the LoadBalancerName of external load balancers passed through the InstanceGroupSpec
// We lookup the LoadBalancerName for LoadBalancer tasks that don't have it set, in order to attach the LB to the ASG
// To prevent spurious changes being reported, we need to regenerate those tasks to be identical when Finding them from AWS
// Because we don't know whether any given LoadBalancerName attached to an ASG is the API ELB task or not,
// we have to find the API ELB task, lookup its LoadBalancerName, and then compare that to the list of attached LoadBalancers
// in order to make the tasks returned from Find identical to the ones generated by the model.
var apiLBTask *LoadBalancer
var apiLBDesc *elb.LoadBalancerDescription
for _, lb := range e.LoadBalancers {
if !fi.BoolValue(lb.Shared) {
apiLBTask = lb
}
}
if apiLBTask != nil {
apiLBDesc, err = FindLoadBalancerByNameTag(c.Cloud.(awsup.AWSCloud), fi.StringValue(apiLBTask.Name))
if err != nil {
return nil, err
}
if apiLBDesc != nil {
for i := 0; i < len(actual.LoadBalancers); i++ {
lb := actual.LoadBalancers[i]
if aws.StringValue(apiLBDesc.LoadBalancerName) == aws.StringValue(lb.Name) {
actual.LoadBalancers[i] = apiLBTask
}
}
}
}
}

for _, tg := range g.TargetGroupARNs {
actual.TargetGroups = append(actual.TargetGroups, &TargetGroup{ARN: aws.String(*tg)})
}
Expand Down

0 comments on commit ee430a3

Please sign in to comment.