Skip to content

Commit 7c7bc8e

Browse files
authored
Merge pull request #4323 from zac-nixon/main
[gw api] add grpc e2e tests
2 parents 73b036f + bfeef76 commit 7c7bc8e

File tree

9 files changed

+1255
-25
lines changed

9 files changed

+1255
-25
lines changed

test/e2e/gateway/alb_instance_target_test.go

Lines changed: 336 additions & 7 deletions
Large diffs are not rendered by default.

test/e2e/gateway/alb_ip_target_test.go

Lines changed: 352 additions & 8 deletions
Large diffs are not rendered by default.

test/e2e/gateway/alb_resource_stack.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
1111
)
1212

13-
func newALBResourceStack(dp *appsv1.Deployment, svc *corev1.Service, gwc *gwv1.GatewayClass, gw *gwv1.Gateway, lbc *elbv2gw.LoadBalancerConfiguration, tgc *elbv2gw.TargetGroupConfiguration, lrc *elbv2gw.ListenerRuleConfiguration, httpr []*gwv1.HTTPRoute, baseName string, enablePodReadinessGate bool) *albResourceStack {
13+
func newALBResourceStack(dps []*appsv1.Deployment, svcs []*corev1.Service, gwc *gwv1.GatewayClass, gw *gwv1.Gateway, lbc *elbv2gw.LoadBalancerConfiguration, tgcs []*elbv2gw.TargetGroupConfiguration, lrc *elbv2gw.ListenerRuleConfiguration, httpr []*gwv1.HTTPRoute, grpcrs []*gwv1.GRPCRoute, baseName string, enablePodReadinessGate bool) *albResourceStack {
1414

15-
commonStack := newCommonResourceStack([]*appsv1.Deployment{dp}, []*corev1.Service{svc}, gwc, gw, lbc, []*elbv2gw.TargetGroupConfiguration{tgc}, []*elbv2gw.ListenerRuleConfiguration{lrc}, baseName, enablePodReadinessGate)
15+
commonStack := newCommonResourceStack(dps, svcs, gwc, gw, lbc, tgcs, []*elbv2gw.ListenerRuleConfiguration{lrc}, baseName, enablePodReadinessGate)
1616
return &albResourceStack{
1717
httprs: httpr,
18+
grpcrs: grpcrs,
1819
commonStack: commonStack,
1920
}
2021
}
@@ -23,13 +24,21 @@ func newALBResourceStack(dp *appsv1.Deployment, svc *corev1.Service, gwc *gwv1.G
2324
type albResourceStack struct {
2425
commonStack *commonResourceStack
2526
httprs []*gwv1.HTTPRoute
27+
grpcrs []*gwv1.GRPCRoute
2628
}
2729

2830
func (s *albResourceStack) Deploy(ctx context.Context, f *framework.Framework) error {
2931
return s.commonStack.Deploy(ctx, f, func(ctx context.Context, f *framework.Framework, namespace string) error {
30-
for _, httpr := range s.httprs {
31-
httpr.Namespace = namespace
32-
if err := s.createHTTPRoute(ctx, f, httpr); err != nil {
32+
for i := range s.httprs {
33+
s.httprs[i].Namespace = namespace
34+
if err := s.createHTTPRoute(ctx, f, s.httprs[i]); err != nil {
35+
return err
36+
}
37+
}
38+
39+
for i := range s.grpcrs {
40+
s.grpcrs[i].Namespace = namespace
41+
if err := s.createGRPCRoute(ctx, f, s.grpcrs[i]); err != nil {
3342
return err
3443
}
3544
}
@@ -58,6 +67,16 @@ func (s *albResourceStack) createHTTPRoute(ctx context.Context, f *framework.Fra
5867
return f.K8sClient.Create(ctx, httpr)
5968
}
6069

70+
func (s *albResourceStack) createGRPCRoute(ctx context.Context, f *framework.Framework, grpcr *gwv1.GRPCRoute) error {
71+
f.Logger.Info("creating grpc route", "grpc", k8s.NamespacedName(grpcr))
72+
return f.K8sClient.Create(ctx, grpcr)
73+
}
74+
75+
func (s *albResourceStack) updateGRPCRoute(ctx context.Context, f *framework.Framework, grpcr *gwv1.GRPCRoute) error {
76+
f.Logger.Info("updating grpc route", "grpc", k8s.NamespacedName(grpcr))
77+
return f.K8sClient.Update(ctx, grpcr)
78+
}
79+
6180
func (s *albResourceStack) deleteHTTPRoute(ctx context.Context, f *framework.Framework, httpr *gwv1.HTTPRoute) error {
6281
return f.K8sClient.Delete(ctx, httpr)
6382
}

test/e2e/gateway/alb_test_helper.go

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ package gateway
22

33
import (
44
"context"
5+
"crypto/tls"
6+
"fmt"
7+
"google.golang.org/grpc"
8+
"google.golang.org/grpc/credentials"
9+
appsv1 "k8s.io/api/apps/v1"
510
corev1 "k8s.io/api/core/v1"
611
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
12+
"sigs.k8s.io/aws-load-balancer-controller/test/e2e/gateway/grpc/echo"
713
"sigs.k8s.io/aws-load-balancer-controller/test/framework"
814
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
915
)
@@ -12,7 +18,7 @@ type ALBTestStack struct {
1218
albResourceStack *albResourceStack
1319
}
1420

15-
func (s *ALBTestStack) Deploy(ctx context.Context, auxiliaryStack *auxiliaryResourceStack, f *framework.Framework, gwListeners []gwv1.Listener, httprs []*gwv1.HTTPRoute, lbConfSpec elbv2gw.LoadBalancerConfigurationSpec, tgConfSpec elbv2gw.TargetGroupConfigurationSpec, lrConfSpec elbv2gw.ListenerRuleConfigurationSpec, readinessGateEnabled bool) error {
21+
func (s *ALBTestStack) DeployHTTP(ctx context.Context, auxiliaryStack *auxiliaryResourceStack, f *framework.Framework, gwListeners []gwv1.Listener, httprs []*gwv1.HTTPRoute, lbConfSpec elbv2gw.LoadBalancerConfigurationSpec, tgConfSpec elbv2gw.TargetGroupConfigurationSpec, lrConfSpec elbv2gw.ListenerRuleConfigurationSpec, readinessGateEnabled bool) error {
1622
if auxiliaryStack != nil {
1723
gwListeners = append(gwListeners, gwv1.Listener{
1824
Name: "other-ns",
@@ -23,15 +29,38 @@ func (s *ALBTestStack) Deploy(ctx context.Context, auxiliaryStack *auxiliaryReso
2329
httprs = append(httprs, buildOtherNsRefHttpRoute("other-ns", auxiliaryStack.ns))
2430
}
2531

26-
dp := buildDeploymentSpec(f.Options.TestImageRegistry)
2732
svc := buildServiceSpec()
33+
tgc := buildTargetGroupConfig(defaultTgConfigName, tgConfSpec, svc)
34+
return s.deploy(ctx, f, gwListeners, httprs, []*gwv1.GRPCRoute{}, []*appsv1.Deployment{buildDeploymentSpec(f.Options.TestImageRegistry)}, []*corev1.Service{svc}, lbConfSpec, []*elbv2gw.TargetGroupConfiguration{tgc}, lrConfSpec, readinessGateEnabled)
35+
}
36+
37+
func (s *ALBTestStack) DeployGRPC(ctx context.Context, f *framework.Framework, gwListeners []gwv1.Listener, grpcrs []*gwv1.GRPCRoute, lbConfSpec elbv2gw.LoadBalancerConfigurationSpec, tgConfSpec elbv2gw.TargetGroupConfigurationSpec, lrConfSpec elbv2gw.ListenerRuleConfigurationSpec, readinessGateEnabled bool) error {
38+
labels := map[string]string{
39+
"app.kubernetes.io/instance": grpcDefaultName,
40+
}
41+
42+
otherLabels := map[string]string{
43+
"app.kubernetes.io/instance": "other",
44+
}
45+
46+
svc := buildGRPCServiceSpec(grpcDefaultName, labels)
47+
dp := buildGRPCDeploymentSpec(grpcDefaultName, "Hello World", labels)
48+
tgc := buildTargetGroupConfig(defaultTgConfigName, tgConfSpec, svc)
49+
50+
svcOther := buildGRPCServiceSpec(grpcDefaultName+"-other", otherLabels)
51+
dpOther := buildGRPCDeploymentSpec(grpcDefaultName+"-other", "Hello World - Other", otherLabels)
52+
tgcOther := buildTargetGroupConfig(defaultTgConfigName+"-other", tgConfSpec, svcOther)
53+
54+
return s.deploy(ctx, f, gwListeners, []*gwv1.HTTPRoute{}, grpcrs, []*appsv1.Deployment{dp, dpOther}, []*corev1.Service{svc, svcOther}, lbConfSpec, []*elbv2gw.TargetGroupConfiguration{tgc, tgcOther}, lrConfSpec, readinessGateEnabled)
55+
}
56+
57+
func (s *ALBTestStack) deploy(ctx context.Context, f *framework.Framework, gwListeners []gwv1.Listener, httprs []*gwv1.HTTPRoute, grpcrs []*gwv1.GRPCRoute, dps []*appsv1.Deployment, svcs []*corev1.Service, lbConfSpec elbv2gw.LoadBalancerConfigurationSpec, tgcs []*elbv2gw.TargetGroupConfiguration, lrConfSpec elbv2gw.ListenerRuleConfigurationSpec, readinessGateEnabled bool) error {
2858
gwc := buildGatewayClassSpec("gateway.k8s.aws/alb")
2959
gw := buildBasicGatewaySpec(gwc, gwListeners)
3060
lbc := buildLoadBalancerConfig(lbConfSpec)
31-
tgc := buildTargetGroupConfig(defaultTgConfigName, tgConfSpec, svc)
3261
lrc := buildListenerRuleConfig(defaultLRConfigName, lrConfSpec)
3362

34-
s.albResourceStack = newALBResourceStack(dp, svc, gwc, gw, lbc, tgc, lrc, httprs, "alb-gateway-e2e", readinessGateEnabled)
63+
s.albResourceStack = newALBResourceStack(dps, svcs, gwc, gw, lbc, tgcs, lrc, httprs, grpcrs, "alb-gateway-e2e", readinessGateEnabled)
3564

3665
return s.albResourceStack.Deploy(ctx, f)
3766
}
@@ -58,3 +87,16 @@ func (s *ALBTestStack) GetWorkerNodes(ctx context.Context, f *framework.Framewor
5887
}
5988
return nodeList, nil
6089
}
90+
91+
func generateGRPCClient(dnsName string) (echo.EchoServiceClient, error) {
92+
target := fmt.Sprintf("%s:443", dnsName)
93+
tlsConfig := &tls.Config{
94+
InsecureSkipVerify: true, // This skips all certificate verification, including expiry.
95+
}
96+
97+
conn, err := grpc.NewClient(target, grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
98+
if err != nil {
99+
return nil, err
100+
}
101+
return echo.NewEchoServiceClient(conn), nil
102+
}

test/e2e/gateway/consts.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import (
1111
const (
1212
appContainerPort = 80
1313
udpContainerPort = 8080
14+
grpcContainerPort = 50051
1415
defaultNumReplicas = 3
1516
defaultName = "gateway-e2e"
1617
udpDefaultName = defaultName + "-udp"
18+
grpcDefaultName = defaultName + "-grpc"
1719
defaultGatewayClassName = "gwclass-e2e"
1820
defaultLbConfigName = "lbconfig-e2e"
1921
defaultTgConfigName = "tgconfig-e2e"
@@ -47,6 +49,17 @@ var DEFAULT_ALB_TARGET_GROUP_HC = &verifier.TargetGroupHC{
4749
UnhealthyThreshold: 3,
4850
}
4951

52+
// Common settings for ALB target group health checks using GRPC
53+
var DEFAULT_ALB_TARGET_GROUP_HC_GRPC = &verifier.TargetGroupHC{
54+
Protocol: "HTTP",
55+
Port: "traffic-port",
56+
Path: "/AWS.ALB/healthcheck",
57+
Interval: 15,
58+
Timeout: 5,
59+
HealthyThreshold: 3,
60+
UnhealthyThreshold: 3,
61+
}
62+
5063
var listenerConfigurationForHeaderModification = &[]elbv2gw.ListenerConfiguration{
5164
{
5265
ProtocolPort: "HTTP:80",
@@ -75,6 +88,18 @@ var DefaultHttpRouteRuleBackendRefs = []gwv1.HTTPBackendRef{
7588
},
7689
}
7790

91+
var defaultGrpcPort = gwalpha2.PortNumber(50051)
92+
var DefaultGrpcRouteRuleBackendRefs = []gwv1.GRPCBackendRef{
93+
{
94+
BackendRef: gwv1.BackendRef{
95+
BackendObjectReference: gwv1.BackendObjectReference{
96+
Name: grpcDefaultName,
97+
Port: &defaultGrpcPort,
98+
},
99+
},
100+
},
101+
}
102+
78103
var portNew = gwalpha2.PortNumber(8443)
79104
var httpRouteRuleWithMatchesAndFilters = []gwv1.HTTPRouteRule{
80105
{

0 commit comments

Comments
 (0)