Skip to content

Commit f0adafb

Browse files
authored
target group name based on tgt port (#1522)
1 parent 283db67 commit f0adafb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pkg/service/nlb/builder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,18 @@ func (t *defaultModelBuildTask) buildListeners(ctx context.Context, ec2Subnets [
410410
}
411411

412412
svcPort := intstr.FromInt(int(port.Port))
413-
tgName := t.buildTargetGroupName(ctx, svcPort, elbv2model.TargetTypeIP, tgProtocol, hc)
413+
tgName := t.buildTargetGroupName(ctx, port.TargetPort, elbv2model.TargetTypeIP, tgProtocol, hc)
414414
tgResId := t.buildTargetGroupResourceID(k8s.NamespacedName(t.service), svcPort)
415+
targetPort := 1
416+
if port.TargetPort.Type == intstr.Int {
417+
targetPort = port.TargetPort.IntValue()
418+
}
415419
targetGroup, exists := targetGroupMap[port.TargetPort.String()]
416420
if !exists {
417421
targetGroup = elbv2model.NewTargetGroup(t.stack, tgResId, elbv2model.TargetGroupSpec{
418422
Name: tgName,
419423
TargetType: elbv2model.TargetTypeIP,
420-
Port: int64(port.TargetPort.IntValue()),
424+
Port: int64(targetPort),
421425
Protocol: tgProtocol,
422426
HealthCheckConfig: hc,
423427
TargetGroupAttributes: tgAttrs,

pkg/service/nlb/builder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ func Test_defaultModelBuilderTask_buildNLB(t *testing.T) {
582582
},
583583
"default/nlb-ip-svc-tls:83":{
584584
"spec":{
585-
"name":"k8s-default-nlbipsvc-00cd37875f",
585+
"name":"k8s-default-nlbipsvc-4cde48cd00",
586586
"targetType":"ip",
587587
"port":8883,
588588
"protocol":"TCP",
@@ -659,7 +659,7 @@ func Test_defaultModelBuilderTask_buildNLB(t *testing.T) {
659659
"spec":{
660660
"template":{
661661
"metadata":{
662-
"name":"k8s-default-nlbipsvc-00cd37875f",
662+
"name":"k8s-default-nlbipsvc-4cde48cd00",
663663
"namespace":"default",
664664
"creationTimestamp":null
665665
},

0 commit comments

Comments
 (0)