refactor: Drop TargetGroups from NetworkLoadBalancer task

They are not needed, they were only used for dependency ordering (and
we now have that dependency on the split out listener task)
This commit is contained in:
justinsb 2024-01-28 18:25:33 -05:00
parent 61842d1e45
commit bd8cce06ae
3 changed files with 2 additions and 62 deletions

View File

@ -202,7 +202,6 @@ func (b *APILoadBalancerBuilder) Build(c *fi.CloudupModelBuilderContext) error {
b.LinkToELBSecurityGroup("api"),
},
SubnetMappings: nlbSubnetMappings,
TargetGroups: make([]*awstasks.TargetGroup, 0),
Tags: tags,
WellKnownServices: []wellknownservices.WellKnownService{wellknownservices.KubeAPIServer},
@ -323,8 +322,6 @@ func (b *APILoadBalancerBuilder) Build(c *fi.CloudupModelBuilderContext) error {
}
c.AddTask(tg)
nlb.TargetGroups = append(nlb.TargetGroups, tg)
}
if b.Cluster.UsesNoneDNS() {
@ -349,8 +346,6 @@ func (b *APILoadBalancerBuilder) Build(c *fi.CloudupModelBuilderContext) error {
}
c.AddTask(tg)
nlb.TargetGroups = append(nlb.TargetGroups, tg)
}
if lbSpec.SSLCertificate != "" {
@ -373,9 +368,7 @@ func (b *APILoadBalancerBuilder) Build(c *fi.CloudupModelBuilderContext) error {
Shared: fi.PtrTo(false),
}
c.AddTask(secondaryTG)
nlb.TargetGroups = append(nlb.TargetGroups, secondaryTG)
}
sort.Stable(awstasks.OrderTargetGroupsByName(nlb.TargetGroups))
for _, nlbListener := range nlbListeners {
c.AddTask(nlbListener)
}

View File

@ -347,7 +347,6 @@ func (b *BastionModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
SecurityGroups: []*awstasks.SecurityGroup{
b.LinkToELBSecurityGroup("bastion"),
},
TargetGroups: make([]*awstasks.TargetGroup, 0),
Tags: tags,
VPC: b.LinkToVPC(),
@ -394,9 +393,6 @@ func (b *BastionModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
c.AddTask(tg)
nlb.TargetGroups = append(nlb.TargetGroups, tg)
sort.Stable(awstasks.OrderTargetGroupsByName(nlb.TargetGroups))
c.AddTask(nlb)
}

View File

@ -69,7 +69,6 @@ type NetworkLoadBalancer struct {
Type *string
VPC *VPC
TargetGroups []*TargetGroup
AccessLog *NetworkLoadBalancerAccessLog
// WellKnownServices indicates which services are supported by this resource.
@ -196,7 +195,6 @@ func (e *NetworkLoadBalancer) getHostedZoneId() *string {
}
func (e *NetworkLoadBalancer) Find(c *fi.CloudupContext) (*NetworkLoadBalancer, error) {
ctx := c.Context()
cloud := c.T.Cloud.(awsup.AWSCloud)
lb, err := cloud.FindELBV2ByNameTag(e.Tags["Name"])
@ -257,47 +255,6 @@ func (e *NetworkLoadBalancer) Find(c *fi.CloudupContext) (*NetworkLoadBalancer,
actual.SecurityGroups = append(actual.SecurityGroups, &SecurityGroup{ID: sg})
}
{
request := &elbv2.DescribeListenersInput{
LoadBalancerArn: loadBalancerArn,
}
var listeners []*elbv2.Listener
if err := cloud.ELBV2().DescribeListenersPagesWithContext(ctx, request, func(page *elbv2.DescribeListenersOutput, lastPage bool) bool {
listeners = append(listeners, page.Listeners...)
return true
}); err != nil {
return nil, fmt.Errorf("listing NLB listeners: %w", err)
}
actual.TargetGroups = []*TargetGroup{}
for _, l := range listeners {
// This will need to be rearranged when we recognized multiple listeners and target groups per NLB
if len(l.DefaultActions) > 0 {
targetGroupARN := l.DefaultActions[0].TargetGroupArn
if targetGroupARN != nil {
targetGroupName, err := awsup.GetTargetGroupNameFromARN(fi.ValueOf(targetGroupARN))
if err != nil {
return nil, err
}
actual.TargetGroups = append(actual.TargetGroups, &TargetGroup{ARN: targetGroupARN, Name: fi.PtrTo(targetGroupName)})
cloud := c.T.Cloud.(awsup.AWSCloud)
descResp, err := cloud.ELBV2().DescribeTargetGroups(&elbv2.DescribeTargetGroupsInput{
TargetGroupArns: []*string{targetGroupARN},
})
if err != nil {
return nil, fmt.Errorf("error querying for NLB listener target groups: %v", err)
}
if len(descResp.TargetGroups) != 1 {
return nil, fmt.Errorf("unexpected DescribeTargetGroups response: %v", descResp)
}
}
}
}
sort.Stable(OrderTargetGroupsByName(actual.TargetGroups))
}
{
lbAttributes, err := findNetworkLoadBalancerAttributes(cloud, aws.StringValue(loadBalancerArn))
if err != nil {
@ -431,7 +388,6 @@ func (e *NetworkLoadBalancer) Run(c *fi.CloudupContext) error {
func (e *NetworkLoadBalancer) Normalize(c *fi.CloudupContext) error {
// We need to sort our arrays consistently, so we don't get spurious changes
sort.Stable(OrderSubnetMappingsByName(e.SubnetMappings))
sort.Stable(OrderTargetGroupsByName(e.TargetGroups))
e.IpAddressType = fi.PtrTo("dualstack")
for _, subnet := range e.SubnetMappings {
@ -507,11 +463,6 @@ func (_ *NetworkLoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Ne
if e.LoadBalancerName == nil {
return fi.RequiredField("LoadBalancerName")
}
for _, tg := range e.TargetGroups {
if tg.ARN == nil {
return fmt.Errorf("missing required target group ARN for NLB creation %v", tg)
}
}
loadBalancerName = *e.LoadBalancerName