Merge pull request #16288 from justinsb/refactor_nlb_name

refactor: NetworkLoadBalancer Name should match Name tag
This commit is contained in:
Kubernetes Prow Robot 2024-01-28 21:13:26 -08:00 committed by GitHub
commit 2b54ae9d14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 7 deletions

View File

@ -167,16 +167,15 @@ func (b *APILoadBalancerBuilder) Build(c *fi.CloudupModelBuilderContext) error {
klog.V(1).Infof("WARNING: You are overwriting the Load Balancers, Security Group. When this is done you are responsible for ensure the correct rules!") klog.V(1).Infof("WARNING: You are overwriting the Load Balancers, Security Group. When this is done you are responsible for ensure the correct rules!")
} }
tags := b.CloudTags(loadBalancerName, false) tags := b.CloudTags("", false)
for k, v := range b.Cluster.Spec.CloudLabels { for k, v := range b.Cluster.Spec.CloudLabels {
tags[k] = v tags[k] = v
} }
// Override the returned name to be the expected ELB name // Override the returned name to be the expected ELB name
tags["Name"] = "api." + b.ClusterName() tags["Name"] = "api." + b.ClusterName()
name := b.NLBName("api")
nlb = &awstasks.NetworkLoadBalancer{ nlb = &awstasks.NetworkLoadBalancer{
Name: &name, Name: fi.PtrTo(b.NLBName("api")),
Lifecycle: b.Lifecycle, Lifecycle: b.Lifecycle,
LoadBalancerName: fi.PtrTo(loadBalancerName), LoadBalancerName: fi.PtrTo(loadBalancerName),

View File

@ -321,7 +321,7 @@ func (b *BastionModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
{ {
loadBalancerName := b.LBName32("bastion") loadBalancerName := b.LBName32("bastion")
tags := b.CloudTags(loadBalancerName, false) tags := b.CloudTags("", false)
for k, v := range b.Cluster.Spec.CloudLabels { for k, v := range b.Cluster.Spec.CloudLabels {
tags[k] = v tags[k] = v
} }

View File

@ -98,7 +98,7 @@ func (b *KopsModelContext) CLBName(prefix string) string {
} }
func (b *KopsModelContext) NLBName(prefix string) string { func (b *KopsModelContext) NLBName(prefix string) string {
return strings.ReplaceAll(prefix+"-"+b.ClusterName(), ".", "-") return prefix + "." + b.ClusterName()
} }
func (b *KopsModelContext) NLBTargetGroupName(prefix string) string { func (b *KopsModelContext) NLBTargetGroupName(prefix string) string {

View File

@ -160,7 +160,6 @@ func findDNSTargetNLB(cloud awsup.AWSCloud, aliasTarget *route53.AliasTarget, dn
if nameTag == "" { if nameTag == "" {
return nil, fmt.Errorf("Found NLB %q linked to DNS name %q, but it did not have a Name tag", loadBalancerName, fi.ValueOf(targetDNSName)) return nil, fmt.Errorf("Found NLB %q linked to DNS name %q, but it did not have a Name tag", loadBalancerName, fi.ValueOf(targetDNSName))
} }
nameTag = strings.Replace(nameTag, ".", "-", -1)
return &NetworkLoadBalancer{Name: fi.PtrTo(nameTag)}, nil return &NetworkLoadBalancer{Name: fi.PtrTo(nameTag)}, nil
} }
return nil, nil return nil, nil

View File

@ -870,7 +870,7 @@ func (_ *NetworkLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e
listenerTF.Protocol = elbv2.ProtocolEnumTcp listenerTF.Protocol = elbv2.ProtocolEnumTcp
} }
err = t.RenderResource("aws_lb_listener", fmt.Sprintf("%v-%v", *e.Name, listener.Port), listenerTF) err = t.RenderResource("aws_lb_listener", fmt.Sprintf("%v-%v", e.TerraformName(), listener.Port), listenerTF)
if err != nil { if err != nil {
return err return err
} }
@ -879,6 +879,11 @@ func (_ *NetworkLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e
return nil return nil
} }
func (e *NetworkLoadBalancer) TerraformName() string {
tfName := strings.Replace(fi.ValueOf(e.Name), ".", "-", -1)
return tfName
}
func (e *NetworkLoadBalancer) TerraformLink(params ...string) *terraformWriter.Literal { func (e *NetworkLoadBalancer) TerraformLink(params ...string) *terraformWriter.Literal {
prop := "id" prop := "id"
if len(params) > 0 { if len(params) > 0 {