Skip to content

Commit e4f3aed

Browse files
committed
Add E2E test framework for Gateway API
1 parent 31f2748 commit e4f3aed

File tree

8 files changed

+40
-23
lines changed

8 files changed

+40
-23
lines changed

test/e2e/gateway/alb_instance_target.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
88
"sigs.k8s.io/aws-load-balancer-controller/test/framework"
99
"sigs.k8s.io/controller-runtime/pkg/client"
10+
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
1011
)
1112

1213
type ALBInstanceTestStack struct {
@@ -17,7 +18,7 @@ func (s *ALBInstanceTestStack) Deploy(ctx context.Context, f *framework.Framewor
1718
dp := buildDeploymentSpec(f.Options.TestImageRegistry)
1819
svc := buildServiceSpec()
1920
gwc := buildGatewayClassSpec("gateway.k8s.aws/alb")
20-
gw := buildGatewaySpec(gwc)
21+
gw := buildBasicGatewaySpec(gwc, gwv1.HTTPProtocolType)
2122
lbc := buildLoadBalancerConfig(spec)
2223
httpr := buildHTTPRoute()
2324
s.albResourceStack = newALBResourceStack(dp, svc, gwc, gw, lbc, httpr, "service-instance-e2e", false)
@@ -30,6 +31,7 @@ func (s *ALBInstanceTestStack) ScaleDeployment(ctx context.Context, f *framework
3031
}
3132

3233
func (s *ALBInstanceTestStack) Cleanup(ctx context.Context, f *framework.Framework) {
34+
_ = f.K8sClient.Delete(ctx, s.albResourceStack.httpr)
3335
s.albResourceStack.Cleanup(ctx, f)
3436
}
3537

test/e2e/gateway/alb_instance_target_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ var _ = Describe("test k8s alb gateway reconciled by the aws load balancer contr
1919
lbARN string
2020
)
2121
BeforeEach(func() {
22+
if !tf.Options.EnableGatewayTests {
23+
Skip("Skipping gateway tests")
24+
}
2225
ctx = context.Background()
2326
stack = ALBInstanceTestStack{}
2427
})
@@ -62,6 +65,7 @@ var _ = Describe("test k8s alb gateway reconciled by the aws load balancer contr
6265
TargetGroupHC: &verifier.TargetGroupHC{
6366
Protocol: "HTTP",
6467
Port: "traffic-port",
68+
Path: "/",
6569
Interval: 15,
6670
Timeout: 5,
6771
HealthyThreshold: 3,

test/e2e/gateway/alb_resource_stack.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ func (s *albResourceStack) getListenersPortMap() map[string]string {
5353
}
5454

5555
func (s *albResourceStack) getTargetGroupNodePortMap() map[string]string {
56-
return s.commonStack.getTargetGroupNodePortMap()
56+
res := s.commonStack.getTargetGroupNodePortMap()
57+
58+
for p := range res {
59+
// TODO - kinda a hack to get HTTP to work.
60+
if res[p] == string(corev1.ProtocolTCP) {
61+
res[p] = "HTTP"
62+
}
63+
}
64+
65+
return res
5766
}
5867

5968
func (s *albResourceStack) getHealthCheckNodePort() string {

test/e2e/gateway/common_resource_stack.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
appsv1 "k8s.io/api/apps/v1"
77
corev1 "k8s.io/api/core/v1"
8+
apierrs "k8s.io/apimachinery/pkg/api/errors"
89
"k8s.io/apimachinery/pkg/util/wait"
910
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
1011
"sigs.k8s.io/aws-load-balancer-controller/pkg/algorithm"
@@ -107,8 +108,6 @@ func (s *commonResourceStack) ScaleDeployment(ctx context.Context, f *framework.
107108

108109
func (s *commonResourceStack) Cleanup(ctx context.Context, f *framework.Framework) {
109110
_ = s.deleteGateway(ctx, f)
110-
// todo - fix
111-
time.Sleep(5 * time.Minute)
112111
_ = s.deleteNamespace(ctx, f)
113112
_ = s.deleteGatewayClass(ctx, f)
114113
}
@@ -240,7 +239,20 @@ func (s *commonResourceStack) deleteService(ctx context.Context, f *framework.Fr
240239
}
241240

242241
func (s *commonResourceStack) deleteGateway(ctx context.Context, f *framework.Framework) error {
243-
return f.K8sClient.Delete(ctx, s.gw)
242+
err := f.K8sClient.Delete(ctx, s.gw)
243+
if err != nil {
244+
return err
245+
}
246+
observedGW := &gwv1.Gateway{}
247+
return wait.PollImmediateUntil(utils.PollIntervalShort, func() (bool, error) {
248+
if err := f.K8sClient.Get(ctx, k8s.NamespacedName(s.gw), observedGW); err != nil {
249+
if apierrs.IsNotFound(err) {
250+
return true, nil
251+
}
252+
return false, err
253+
}
254+
return false, nil
255+
}, ctx.Done())
244256
}
245257

246258
func (s *commonResourceStack) deleteGatewayClass(ctx context.Context, f *framework.Framework) error {

test/e2e/gateway/nlb_instance_target.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
88
"sigs.k8s.io/aws-load-balancer-controller/test/framework"
99
"sigs.k8s.io/controller-runtime/pkg/client"
10+
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
1011
)
1112

1213
type NLBInstanceTestStack struct {
@@ -17,7 +18,7 @@ func (s *NLBInstanceTestStack) Deploy(ctx context.Context, f *framework.Framewor
1718
dp := buildDeploymentSpec(f.Options.TestImageRegistry)
1819
svc := buildServiceSpec()
1920
gwc := buildGatewayClassSpec("gateway.k8s.aws/nlb")
20-
gw := buildGatewaySpec(gwc)
21+
gw := buildBasicGatewaySpec(gwc, gwv1.TCPProtocolType)
2122
lbc := buildLoadBalancerConfig(spec)
2223
tcpr := buildTCPRoute()
2324
s.nlbResourceStack = newNLBResourceStack(dp, svc, gwc, gw, lbc, tcpr, "service-instance-e2e", false)
@@ -30,6 +31,7 @@ func (s *NLBInstanceTestStack) ScaleDeployment(ctx context.Context, f *framework
3031
}
3132

3233
func (s *NLBInstanceTestStack) Cleanup(ctx context.Context, f *framework.Framework) {
34+
_ = f.K8sClient.Delete(ctx, s.nlbResourceStack.tcpr)
3335
s.nlbResourceStack.Cleanup(ctx, f)
3436
}
3537

test/e2e/gateway/nlb_instance_target_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ var _ = Describe("test nlb gateway reconciled by the aws load balancer controlle
1919
lbARN string
2020
)
2121
BeforeEach(func() {
22+
if !tf.Options.EnableGatewayTests {
23+
Skip("Skipping gateway tests")
24+
}
2225
ctx = context.Background()
2326
stack = NLBInstanceTestStack{}
2427
})

test/e2e/gateway/shared_resource_definitions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func buildLoadBalancerConfig(spec elbv2gw.LoadBalancerConfigurationSpec) *elbv2g
9898
return lbc
9999
}
100100

101-
func buildGatewaySpec(gwc *gwv1.GatewayClass) *gwv1.Gateway {
101+
func buildBasicGatewaySpec(gwc *gwv1.GatewayClass, protocol gwv1.ProtocolType) *gwv1.Gateway {
102102
gw := &gwv1.Gateway{
103103
ObjectMeta: metav1.ObjectMeta{
104104
Name: defaultName,
@@ -109,7 +109,7 @@ func buildGatewaySpec(gwc *gwv1.GatewayClass) *gwv1.Gateway {
109109
{
110110
Name: "test-listener",
111111
Port: 80,
112-
Protocol: gwv1.TCPProtocolType,
112+
Protocol: protocol,
113113
},
114114
},
115115
Infrastructure: &gwv1.GatewayInfrastructure{
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package ingress
22

33
import (
4-
"fmt"
54
. "github.com/onsi/ginkgo/v2"
65
. "github.com/onsi/gomega"
76
framework "sigs.k8s.io/aws-load-balancer-controller/test/framework"
87
"testing"
9-
"time"
108
)
119

1210
var tf *framework.Framework
@@ -17,22 +15,9 @@ func TestIngress(t *testing.T) {
1715
}
1816

1917
var _ = BeforeSuite(func() {
20-
21-
fmt.Println("before!")
2218
var err error
2319

24-
defer func() {
25-
fmt.Println("Hello!?")
26-
if r := recover(); r != nil {
27-
fmt.Println("Recovered in f", r)
28-
}
29-
}()
30-
3120
tf, err = framework.InitFramework()
3221

33-
fmt.Println("after!")
34-
35-
time.Sleep(10 * time.Second)
36-
3722
Expect(err).NotTo(HaveOccurred())
3823
})

0 commit comments

Comments
 (0)