Address feedback

This commit is contained in:
Peter Rifel 2020-11-09 17:24:32 -06:00
parent 54decbc479
commit 4758ea9f2f
No known key found for this signature in database
GPG Key ID: BC6469E5B16DB2B6
3 changed files with 19 additions and 22 deletions

View File

@ -204,16 +204,16 @@ func (b *APILoadBalancerBuilder) Build(c *fi.ModelBuilderContext) error {
c.AddTask(clb)
} else if b.APILoadBalancerClass() == kops.LoadBalancerClassNetwork {
targetGroupName := b.NLBTargetGroupName("tcp")
primaryTags := b.CloudTags(targetGroupName, false)
tcpGroupName := b.NLBTargetGroupName("tcp")
tcpGroupTags := b.CloudTags(tcpGroupName, false)
// Override the returned name to be the expected NLB TG name
primaryTags["Name"] = targetGroupName
tcpGroupTags["Name"] = tcpGroupName
tg := &awstasks.TargetGroup{
Name: fi.String(targetGroupName),
Name: fi.String(tcpGroupName),
VPC: b.LinkToVPC(),
Tags: primaryTags,
Tags: tcpGroupTags,
Protocol: fi.String("TCP"),
Port: fi.Int64(443),
HealthyThreshold: fi.Int64(2),
@ -226,15 +226,15 @@ func (b *APILoadBalancerBuilder) Build(c *fi.ModelBuilderContext) error {
nlb.TargetGroups = append(nlb.TargetGroups, tg)
if lbSpec.SSLCertificate != "" {
secondaryTags := b.CloudTags(targetGroupName, false)
secondaryName := b.NLBTargetGroupName("tls")
tlsGroupName := b.NLBTargetGroupName("tls")
tlsGroupTags := b.CloudTags(tlsGroupName, false)
// Override the returned name to be the expected NLB TG name
secondaryTags["Name"] = secondaryName
tlsGroupTags["Name"] = tlsGroupName
secondaryTG := &awstasks.TargetGroup{
Name: fi.String(secondaryName),
Name: fi.String(tlsGroupName),
VPC: b.LinkToVPC(),
Tags: secondaryTags,
Tags: tlsGroupTags,
Protocol: fi.String("TLS"),
Port: fi.Int64(443),
HealthyThreshold: fi.Int64(2),
@ -244,7 +244,7 @@ func (b *APILoadBalancerBuilder) Build(c *fi.ModelBuilderContext) error {
c.AddTask(secondaryTG)
nlb.TargetGroups = append(nlb.TargetGroups, secondaryTG)
}
sort.Stable(awstasks.OrderTargetGroupsByPort(nlb.TargetGroups))
sort.Stable(awstasks.OrderTargetGroupsByName(nlb.TargetGroups))
c.AddTask(nlb)
}

View File

@ -123,7 +123,7 @@ func (e *NetworkLoadBalancerListener) GetDependencies(tasks map[string]fi.Task)
return nil
}
// OrderListenersByPort implements sort.Interface for []OrderTargetGroupsByPort, based on port number
// OrderListenersByPort implements sort.Interface for []OrderListenersByPort, based on port number
type OrderListenersByPort []*NetworkLoadBalancerListener
func (a OrderListenersByPort) Len() int { return len(a) }
@ -336,7 +336,6 @@ func (e *NetworkLoadBalancer) Find(c *fi.Context) (*NetworkLoadBalancer, error)
actual.Scheme = lb.Scheme
actual.VPC = &VPC{ID: lb.VpcId}
actual.Type = lb.Type
actual.TargetGroups = make([]*TargetGroup, 0)
tagMap, err := describeNetworkLoadBalancerTags(cloud, []string{*loadBalancerArn})
if err != nil {
@ -363,8 +362,6 @@ func (e *NetworkLoadBalancer) Find(c *fi.Context) (*NetworkLoadBalancer, error)
return nil, fmt.Errorf("error querying for NLB listeners :%v", err)
}
actual.Listeners = make([]*NetworkLoadBalancerListener, 0)
for _, l := range response.Listeners {
actualListener := &NetworkLoadBalancerListener{}
actualListener.Port = int(aws.Int64Value(l.Port))
@ -400,7 +397,7 @@ func (e *NetworkLoadBalancer) Find(c *fi.Context) (*NetworkLoadBalancer, error)
}
actual.TargetGroups = targetGroups
}
sort.Stable(OrderTargetGroupsByPort(actual.TargetGroups))
sort.Stable(OrderTargetGroupsByName(actual.TargetGroups))
}
@ -494,7 +491,7 @@ func (e *NetworkLoadBalancer) Normalize() {
// We need to sort our arrays consistently, so we don't get spurious changes
sort.Stable(OrderSubnetsById(e.Subnets))
sort.Stable(OrderListenersByPort(e.Listeners))
sort.Stable(OrderTargetGroupsByPort(e.TargetGroups))
sort.Stable(OrderTargetGroupsByName(e.TargetGroups))
}
func (s *NetworkLoadBalancer) CheckChanges(a, e, changes *NetworkLoadBalancer) error {

View File

@ -194,12 +194,12 @@ func (_ *TargetGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *TargetGrou
return nil
}
// OrderTargetGroupsByPort implements sort.Interface for []OrderTargetGroupsByPort, based on port number
type OrderTargetGroupsByPort []*TargetGroup
// OrderTargetGroupsByName implements sort.Interface for []OrderTargetGroupsByName, based on port number
type OrderTargetGroupsByName []*TargetGroup
func (a OrderTargetGroupsByPort) Len() int { return len(a) }
func (a OrderTargetGroupsByPort) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a OrderTargetGroupsByPort) Less(i, j int) bool {
func (a OrderTargetGroupsByName) Len() int { return len(a) }
func (a OrderTargetGroupsByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a OrderTargetGroupsByName) Less(i, j int) bool {
if a[i].ARN != nil || a[j].ARN != nil {
return fi.StringValue(a[i].ARN) < fi.StringValue(a[j].ARN)
}