Skip to content

Commit dca1d54

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

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var _ = Describe("test k8s alb gateway reconciled by the aws load balancer contr
6262
TargetGroupHC: &verifier.TargetGroupHC{
6363
Protocol: "HTTP",
6464
Port: "traffic-port",
65+
Path: "/",
6566
Interval: 15,
6667
Timeout: 5,
6768
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 & 1 deletion
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"
@@ -240,7 +241,20 @@ func (s *commonResourceStack) deleteService(ctx context.Context, f *framework.Fr
240241
}
241242

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

246260
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/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{

0 commit comments

Comments
 (0)