Skip to content

Commit 21e6c0a

Browse files
authored
Add E2E tests that validate route statuses are properly set (#4362)
* initial route status e2e test * add route status validation into e2e tests * refactor to remove code duplication
1 parent 04ce65e commit 21e6c0a

File tree

7 files changed

+354
-1
lines changed

7 files changed

+354
-1
lines changed

test/e2e/gateway/alb_instance_target_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ var _ = Describe("test k8s alb gateway using instance targets reconciled by the
141141
err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(503))
142142
Expect(err).NotTo(HaveOccurred())
143143
})
144+
By("confirming the route status", func() {
145+
validateHTTPRouteStatusNotPermitted(tf, stack)
146+
})
144147
By("deploying ref grant", func() {
145148
err := auxiliaryStack.CreateReferenceGrants(ctx, tf, stack.albResourceStack.commonStack.ns)
146149
Expect(err).NotTo(HaveOccurred())
@@ -180,6 +183,9 @@ var _ = Describe("test k8s alb gateway using instance targets reconciled by the
180183
err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(200))
181184
Expect(err).NotTo(HaveOccurred())
182185
})
186+
By("confirming the http route status after ref grant is materialized", func() {
187+
validateHTTPRouteStatusPermitted(tf, stack)
188+
})
183189
By("removing ref grant", func() {
184190
err := auxiliaryStack.DeleteReferenceGrants(ctx, tf)
185191
Expect(err).NotTo(HaveOccurred())
@@ -191,6 +197,9 @@ var _ = Describe("test k8s alb gateway using instance targets reconciled by the
191197
err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(503))
192198
Expect(err).NotTo(HaveOccurred())
193199
})
200+
By("confirming the route status", func() {
201+
validateHTTPRouteStatusNotPermitted(tf, stack)
202+
})
194203
})
195204
})
196205

@@ -1707,6 +1716,9 @@ var _ = Describe("test k8s alb gateway using instance targets reconciled by the
17071716
_, err = c.Echo(mdCtx, &echo.EchoRequest{Message: "foo"})
17081717
Expect(err).ToNot(HaveOccurred())
17091718
})
1719+
By("confirming the route status", func() {
1720+
validateGRPCRouteStatus(tf, stack)
1721+
})
17101722
})
17111723
})
17121724
})

test/e2e/gateway/alb_ip_target_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ var _ = Describe("test k8s alb gateway using ip targets reconciled by the aws lo
137137
err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(503))
138138
Expect(err).NotTo(HaveOccurred())
139139
})
140+
By("confirming the route status", func() {
141+
validateHTTPRouteStatusNotPermitted(tf, stack)
142+
})
140143
By("deploying ref grant", func() {
141144
err := auxiliaryStack.CreateReferenceGrants(ctx, tf, stack.albResourceStack.commonStack.ns)
142145
Expect(err).NotTo(HaveOccurred())
@@ -174,6 +177,9 @@ var _ = Describe("test k8s alb gateway using ip targets reconciled by the aws lo
174177
err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(200))
175178
Expect(err).NotTo(HaveOccurred())
176179
})
180+
By("confirming the http route status after ref grant is materialized", func() {
181+
validateHTTPRouteStatusPermitted(tf, stack)
182+
})
177183
By("removing ref grant", func() {
178184
err := auxiliaryStack.DeleteReferenceGrants(ctx, tf)
179185
Expect(err).NotTo(HaveOccurred())
@@ -185,6 +191,9 @@ var _ = Describe("test k8s alb gateway using ip targets reconciled by the aws lo
185191
err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(503))
186192
Expect(err).NotTo(HaveOccurred())
187193
})
194+
By("confirming the route status", func() {
195+
validateHTTPRouteStatusNotPermitted(tf, stack)
196+
})
188197
})
189198
})
190199

@@ -1768,6 +1777,9 @@ var _ = Describe("test k8s alb gateway using ip targets reconciled by the aws lo
17681777
_, err = c.Echo(mdCtx, &echo.EchoRequest{Message: "foo"})
17691778
Expect(err).ToNot(HaveOccurred())
17701779
})
1780+
By("confirming the route status", func() {
1781+
validateGRPCRouteStatus(tf, stack)
1782+
})
17711783
})
17721784
})
17731785
})

test/e2e/gateway/alb_test_helper.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"google.golang.org/grpc/credentials"
99
appsv1 "k8s.io/api/apps/v1"
1010
corev1 "k8s.io/api/core/v1"
11+
"k8s.io/apimachinery/pkg/types"
1112
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
13+
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
1214
"sigs.k8s.io/aws-load-balancer-controller/test/e2e/gateway/grpc/echo"
1315
"sigs.k8s.io/aws-load-balancer-controller/test/framework"
1416
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
@@ -105,3 +107,106 @@ func generateGRPCClient(dnsName string) (echo.EchoServiceClient, error) {
105107
}
106108
return echo.NewEchoServiceClient(conn), nil
107109
}
110+
111+
func validateHTTPRouteStatusNotPermitted(tf *framework.Framework, stack ALBTestStack) {
112+
validationInfo := map[string]routeValidationInfo{
113+
k8s.NamespacedName(stack.albResourceStack.httprs[0]).String(): {
114+
parentGatewayName: stack.albResourceStack.commonStack.gw.Name,
115+
listenerInfo: []listenerValidationInfo{
116+
{
117+
listenerName: "test-listener",
118+
parentKind: "Gateway",
119+
resolvedRefReason: "Accepted",
120+
resolvedRefsStatus: "True",
121+
acceptedReason: "Accepted",
122+
acceptedStatus: "True",
123+
},
124+
},
125+
},
126+
k8s.NamespacedName(stack.albResourceStack.httprs[1]).String(): {
127+
parentGatewayName: stack.albResourceStack.commonStack.gw.Name,
128+
listenerInfo: []listenerValidationInfo{
129+
{
130+
listenerName: "other-ns",
131+
parentKind: "Gateway",
132+
resolvedRefReason: "RefNotPermitted",
133+
resolvedRefsStatus: "False",
134+
acceptedReason: "RefNotPermitted",
135+
acceptedStatus: "False",
136+
},
137+
},
138+
},
139+
}
140+
validateRouteStatus(tf, stack.albResourceStack.httprs, httpRouteStatusConverter, validationInfo)
141+
}
142+
143+
func validateHTTPRouteStatusPermitted(tf *framework.Framework, stack ALBTestStack) {
144+
validationInfo := map[string]routeValidationInfo{
145+
k8s.NamespacedName(stack.albResourceStack.httprs[0]).String(): {
146+
parentGatewayName: stack.albResourceStack.commonStack.gw.Name,
147+
listenerInfo: []listenerValidationInfo{
148+
{
149+
listenerName: "test-listener",
150+
parentKind: "Gateway",
151+
resolvedRefReason: "Accepted",
152+
resolvedRefsStatus: "True",
153+
acceptedReason: "Accepted",
154+
acceptedStatus: "True",
155+
},
156+
},
157+
},
158+
k8s.NamespacedName(stack.albResourceStack.httprs[1]).String(): {
159+
parentGatewayName: stack.albResourceStack.commonStack.gw.Name,
160+
listenerInfo: []listenerValidationInfo{
161+
{
162+
listenerName: "other-ns",
163+
parentKind: "Gateway",
164+
resolvedRefReason: "Accepted",
165+
resolvedRefsStatus: "True",
166+
acceptedReason: "Accepted",
167+
acceptedStatus: "True",
168+
},
169+
},
170+
},
171+
}
172+
validateRouteStatus(tf, stack.albResourceStack.httprs, httpRouteStatusConverter, validationInfo)
173+
}
174+
175+
func validateGRPCRouteStatus(tf *framework.Framework, stack ALBTestStack) {
176+
validationInfo := map[string]routeValidationInfo{
177+
k8s.NamespacedName(stack.albResourceStack.grpcrs[0]).String(): {
178+
parentGatewayName: stack.albResourceStack.commonStack.gw.Name,
179+
listenerInfo: []listenerValidationInfo{
180+
{
181+
listenerName: "test-listener",
182+
parentKind: "Gateway",
183+
resolvedRefReason: "Accepted",
184+
resolvedRefsStatus: "True",
185+
acceptedReason: "Accepted",
186+
acceptedStatus: "True",
187+
},
188+
},
189+
},
190+
}
191+
validateRouteStatus(tf, stack.albResourceStack.grpcrs, grpcRouteStatusConverter, validationInfo)
192+
}
193+
194+
func httpRouteStatusConverter(tf *framework.Framework, i interface{}) (gwv1.RouteStatus, types.NamespacedName, error) {
195+
httpR := i.(*gwv1.HTTPRoute)
196+
retrievedRoute := gwv1.HTTPRoute{}
197+
err := tf.K8sClient.Get(context.Background(), k8s.NamespacedName(httpR), &retrievedRoute)
198+
if err != nil {
199+
return gwv1.RouteStatus{}, types.NamespacedName{}, err
200+
}
201+
return retrievedRoute.Status.RouteStatus, k8s.NamespacedName(&retrievedRoute), nil
202+
}
203+
204+
func grpcRouteStatusConverter(tf *framework.Framework, i interface{}) (gwv1.RouteStatus, types.NamespacedName, error) {
205+
grpcR := i.(*gwv1.GRPCRoute)
206+
retrievedRoute := gwv1.GRPCRoute{}
207+
err := tf.K8sClient.Get(context.Background(), k8s.NamespacedName(grpcR), &retrievedRoute)
208+
if err != nil {
209+
return gwv1.RouteStatus{}, types.NamespacedName{}, err
210+
}
211+
return retrievedRoute.Status.RouteStatus, k8s.NamespacedName(&retrievedRoute), nil
212+
}

test/e2e/gateway/nlb_instance_target_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ var _ = Describe("test nlb gateway using instance targets reconciled by the aws
155155
err := tf.UDPVerifier.VerifyUDP(endpoint)
156156
Expect(err).NotTo(HaveOccurred())
157157
})
158+
By("confirming the route status", func() {
159+
validateL4RouteStatusNotPermitted(tf, stack, hasTLS)
160+
})
158161
By("deploying ref grant", func() {
159162
err := auxiliaryStack.CreateReferenceGrants(ctx, tf, stack.nlbResourceStack.commonStack.ns)
160163
Expect(err).NotTo(HaveOccurred())
@@ -219,11 +222,14 @@ var _ = Describe("test nlb gateway using instance targets reconciled by the aws
219222
})
220223
Expect(err).NotTo(HaveOccurred())
221224
})
222-
By("sending http request to the lb to the cross ns lsitener", func() {
225+
By("sending http request to the lb to the cross ns listener", func() {
223226
url := fmt.Sprintf("http://%v:5000/any-path", dnsName)
224227
err := tf.HTTPVerifier.VerifyURL(url, http.ResponseCodeMatches(200))
225228
Expect(err).NotTo(HaveOccurred())
226229
})
230+
By("confirming the route status", func() {
231+
validateL4RouteStatusPermitted(tf, stack, hasTLS)
232+
})
227233
By("removing ref grant", func() {
228234
err := auxiliaryStack.DeleteReferenceGrants(ctx, tf)
229235
Expect(err).NotTo(HaveOccurred())
@@ -278,6 +284,14 @@ var _ = Describe("test nlb gateway using instance targets reconciled by the aws
278284
})
279285
Expect(err).NotTo(HaveOccurred())
280286
})
287+
By("sending udp request to the lb", func() {
288+
endpoint := fmt.Sprintf("%v:8080", dnsName)
289+
err := tf.UDPVerifier.VerifyUDP(endpoint)
290+
Expect(err).NotTo(HaveOccurred())
291+
})
292+
By("confirming the route status", func() {
293+
validateL4RouteStatusNotPermitted(tf, stack, hasTLS)
294+
})
281295
})
282296
})
283297
})

test/e2e/gateway/nlb_ip_target_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ var _ = Describe("test nlb gateway using ip targets reconciled by the aws load b
158158
err := tf.UDPVerifier.VerifyUDP(endpoint)
159159
Expect(err).NotTo(HaveOccurred())
160160
})
161+
By("confirming the route status", func() {
162+
validateL4RouteStatusNotPermitted(tf, stack, hasTLS)
163+
})
161164
By("deploying ref grant", func() {
162165
err := auxiliaryStack.CreateReferenceGrants(ctx, tf, stack.nlbResourceStack.commonStack.ns)
163166
Expect(err).NotTo(HaveOccurred())
@@ -219,6 +222,9 @@ var _ = Describe("test nlb gateway using ip targets reconciled by the aws load b
219222
})
220223
Expect(err).NotTo(HaveOccurred())
221224
})
225+
By("confirming the route status", func() {
226+
validateL4RouteStatusPermitted(tf, stack, hasTLS)
227+
})
222228
By("removing ref grant", func() {
223229
err := auxiliaryStack.DeleteReferenceGrants(ctx, tf)
224230
Expect(err).NotTo(HaveOccurred())
@@ -271,6 +277,9 @@ var _ = Describe("test nlb gateway using ip targets reconciled by the aws load b
271277
})
272278
Expect(err).NotTo(HaveOccurred())
273279
})
280+
By("confirming the route status", func() {
281+
validateL4RouteStatusNotPermitted(tf, stack, hasTLS)
282+
})
274283
})
275284
})
276285
}

0 commit comments

Comments
 (0)