Skip to content

Commit 4b49921

Browse files
author
Doyoon Kim
authored
Fix TG creation when using named targetPorts (#243)
* Fix TG creation when using named targetPorts * Used fixed default port 80 when creating HTTP targetgroups
1 parent 0843336 commit 4b49921

File tree

3 files changed

+27
-36
lines changed

3 files changed

+27
-36
lines changed

pkg/gateway/model_build_targetgroup.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gateway
22

33
import (
44
"context"
5+
56
"github.com/golang/glog"
67

78
corev1 "k8s.io/api/core/v1"
@@ -186,7 +187,8 @@ func (t *targetGroupModelBuildTask) BuildTargetGroup(ctx context.Context) error
186187
Type: latticemodel.TargetGroupTypeIP,
187188
Config: latticemodel.TargetGroupConfig{
188189
VpcID: config.VpcID,
189-
//Port: backendServicePort,
190+
// Fill in default HTTP port as we are using target port anyway.
191+
Port: 80,
190192
IsServiceImport: false,
191193
IsServiceExport: true,
192194
K8SServiceName: t.serviceExport.Name,
@@ -196,11 +198,6 @@ func (t *targetGroupModelBuildTask) BuildTargetGroup(ctx context.Context) error
196198
},
197199
}
198200

199-
glog.V(6).Infof("Found backend service port %v , intval %v \n", svc.Spec.Ports[0].TargetPort,
200-
svc.Spec.Ports[0].TargetPort.IntVal)
201-
202-
tgSpec.Config.Port = svc.Spec.Ports[0].TargetPort.IntVal
203-
204201
tg := latticemodel.NewTargetGroup(t.stack, tgName, tgSpec)
205202
glog.V(6).Infof("buildTargetGroup, tg[%s], tgSpec%v \n", tgName, tg)
206203

@@ -290,9 +287,6 @@ func (t *latticeServiceModelBuildTask) buildHTTPTargetGroupSpec(ctx context.Cont
290287
var vpc = config.VpcID
291288
var ekscluster = ""
292289
var isServiceImport bool
293-
var backendServicePort int32
294-
295-
isServiceImport = false
296290

297291
if backendKind == "ServiceImport" {
298292
namespaceName := types.NamespacedName{
@@ -329,14 +323,6 @@ func (t *latticeServiceModelBuildTask) buildHTTPTargetGroupSpec(ctx context.Cont
329323
glog.V(6).Infof("Error finding backend service %v error :%v \n", serviceNamespaceName, err)
330324
return latticemodel.TargetGroupSpec{}, err
331325
}
332-
333-
if svc.Spec.Ports != nil {
334-
glog.V(6).Infof("Found backend service port %v , intval %v \n", svc.Spec.Ports[0].TargetPort,
335-
svc.Spec.Ports[0].TargetPort.IntVal)
336-
337-
backendServicePort = svc.Spec.Ports[0].TargetPort.IntVal
338-
}
339-
340326
}
341327

342328
tgName := latticestore.TargetGroupName(string(httpBackendRef.Name), namespace)
@@ -363,7 +349,8 @@ func (t *latticeServiceModelBuildTask) buildHTTPTargetGroupSpec(ctx context.Cont
363349
K8SHTTPRouteNamespace: t.httpRoute.Namespace,
364350
Protocol: "HTTP",
365351
ProtocolVersion: vpclattice.TargetGroupProtocolVersionHttp1,
366-
Port: backendServicePort,
352+
// Fill in default HTTP port as we are using target port anyway.
353+
Port: 80,
367354
},
368355
IsDeleted: isDeleted,
369356
}, nil

test/suites/integration/httproute_path_match_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package integration
22

33
import (
44
"fmt"
5-
"github.com/aws/aws-application-networking-k8s/pkg/latticestore"
6-
"github.com/aws/aws-application-networking-k8s/test/pkg/test"
7-
"github.com/aws/aws-sdk-go/service/vpclattice"
5+
"log"
6+
"os"
7+
"time"
8+
89
. "github.com/onsi/ginkgo/v2"
910
. "github.com/onsi/gomega"
1011
"github.com/samber/lo"
1112
"k8s.io/apimachinery/pkg/types"
12-
"log"
13-
"os"
1413
"sigs.k8s.io/controller-runtime/pkg/client"
15-
"time"
14+
15+
"github.com/aws/aws-application-networking-k8s/pkg/latticestore"
16+
"github.com/aws/aws-application-networking-k8s/test/pkg/test"
17+
"github.com/aws/aws-sdk-go/service/vpclattice"
1618
)
1719

1820
const (
@@ -21,11 +23,11 @@ const (
2123

2224
var _ = Describe("HTTPRoute path matches", func() {
2325
It("HTTPRoute should support multiple path matches", func() {
24-
gateway := testFramework.NewGateway("",k8snamespace)
26+
gateway := testFramework.NewGateway("", k8snamespace)
2527
deployment1, service1 := testFramework.NewHttpApp(test.HTTPAppOptions{Name: "test-v1", Namespace: k8snamespace})
2628
deployment2, service2 := testFramework.NewHttpApp(test.HTTPAppOptions{Name: "test-v2", Namespace: k8snamespace})
2729
pathMatchHttpRoute := testFramework.NewPathMatchHttpRoute(gateway, []client.Object{service1, service2}, "http",
28-
"", k8snamespace)
30+
"", k8snamespace)
2931

3032
// Create Kubernetes API Objects
3133
testFramework.ExpectCreated(ctx,
@@ -46,7 +48,7 @@ var _ = Describe("HTTPRoute path matches", func() {
4648
Expect(*targetGroupV1.VpcIdentifier).To(Equal(os.Getenv("CLUSTER_VPC_ID")))
4749
Expect(*targetGroupV1.Protocol).To(Equal("HTTP"))
4850
targetsV1 := testFramework.GetTargets(ctx, targetGroupV1, deployment1)
49-
Expect(*targetGroupV1.Port).To(BeEquivalentTo(service1.Spec.Ports[0].TargetPort.IntVal))
51+
Expect(*targetGroupV1.Port).To(BeEquivalentTo(80))
5052
for _, target := range targetsV1 {
5153
Expect(*target.Port).To(BeEquivalentTo(service1.Spec.Ports[0].TargetPort.IntVal))
5254
Expect(*target.Status).To(Or(
@@ -59,7 +61,7 @@ var _ = Describe("HTTPRoute path matches", func() {
5961
Expect(*targetGroupV2.VpcIdentifier).To(Equal(os.Getenv("CLUSTER_VPC_ID")))
6062
Expect(*targetGroupV2.Protocol).To(Equal("HTTP"))
6163
targetsV2 := testFramework.GetTargets(ctx, targetGroupV2, deployment2)
62-
Expect(*targetGroupV2.Port).To(BeEquivalentTo(service2.Spec.Ports[0].TargetPort.IntVal))
64+
Expect(*targetGroupV2.Port).To(BeEquivalentTo(80))
6365
for _, target := range targetsV2 {
6466
Expect(*target.Port).To(BeEquivalentTo(service2.Spec.Ports[0].TargetPort.IntVal))
6567
Expect(*target.Status).To(Or(

test/suites/integration/https_listener_weighted_rule_with_service_export_import_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package integration
22

33
import (
44
"fmt"
5-
"github.com/aws/aws-application-networking-k8s/pkg/latticestore"
6-
"github.com/aws/aws-application-networking-k8s/test/pkg/test"
7-
"github.com/aws/aws-sdk-go/service/vpclattice"
8-
. "github.com/onsi/ginkgo/v2"
9-
. "github.com/onsi/gomega"
10-
"github.com/samber/lo"
11-
appsv1 "k8s.io/api/apps/v1"
125
"log"
136
"os"
147
"strings"
158
"time"
9+
10+
. "github.com/onsi/ginkgo/v2"
11+
. "github.com/onsi/gomega"
12+
"github.com/samber/lo"
13+
appsv1 "k8s.io/api/apps/v1"
14+
15+
"github.com/aws/aws-application-networking-k8s/pkg/latticestore"
16+
"github.com/aws/aws-application-networking-k8s/test/pkg/test"
17+
"github.com/aws/aws-sdk-go/service/vpclattice"
1618
)
1719

1820
var _ = Describe("Test 2 listeners gateway with weighted httproute rules and service export import", func() {
@@ -61,7 +63,7 @@ var _ = Describe("Test 2 listeners gateway with weighted httproute rules and ser
6163
Expect(*retrievedTargetGroupSummary.Protocol).To(Equal("HTTP"))
6264
targets := testFramework.GetTargets(ctx, retrievedTargetGroupSummary, deployments[i])
6365
Expect(len(targets)).To(BeEquivalentTo(1))
64-
Expect(*retrievedTargetGroupSummary.Port).To(BeEquivalentTo(service1.Spec.Ports[0].TargetPort.IntVal))
66+
Expect(*retrievedTargetGroupSummary.Port).To(BeEquivalentTo(80))
6567
for _, target := range targets {
6668
Expect(*target.Port).To(BeEquivalentTo(service1.Spec.Ports[0].TargetPort.IntVal))
6769
Expect(*target.Status).To(Or(

0 commit comments

Comments
 (0)