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

refactor: Drop TargetGroups from NetworkLoadBalancer task #16324

Merged
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
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)
justinsb committed Feb 4, 2024
commit bd8cce06ae5b5d92c389bdfe485eaf74d2eb5670
7 changes: 0 additions & 7 deletions pkg/model/awsmodel/api_loadbalancer.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 0 additions & 4 deletions pkg/model/awsmodel/bastion.go
Original file line number Diff line number Diff line change
@@ -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)
}

53 changes: 2 additions & 51 deletions upup/pkg/fi/cloudup/awstasks/network_load_balancer.go
Original file line number Diff line number Diff line change
@@ -68,9 +68,8 @@ type NetworkLoadBalancer struct {

Type *string

VPC *VPC
TargetGroups []*TargetGroup
AccessLog *NetworkLoadBalancerAccessLog
VPC *VPC
AccessLog *NetworkLoadBalancerAccessLog

// WellKnownServices indicates which services are supported by this resource.
// This field is internal and is not rendered to the cloud.
@@ -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