Skip to content

Commit 9555a9f

Browse files
authored
Refactor(conformance): merge similar helper functions and make the condition check on inferencePool stricter (#1261)
* refactor restructure the conformance tests. * refactor merge helper functions and strict the test cases.
1 parent 8a58a0c commit 9555a9f

7 files changed

+21
-35
lines changed

conformance/tests/epp_unavailable_fail_open.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var EppUnAvailableFailOpen = suite.ConformanceTest{
5757
httpRouteNN := types.NamespacedName{Name: "httproute-for-failopen-pool-gw", Namespace: resources.AppBackendNamespace}
5858
gatewayNN := resources.SecondaryGatewayNN
5959
k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, httpRouteNN, gatewayNN)
60-
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, resources.SecondaryInferencePoolNN)
60+
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, resources.SecondaryInferencePoolNN, gatewayNN)
6161
gwAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, gatewayNN)
6262

6363
pods, err := k8sutils.GetPodsWithLabel(t, s.Client, resources.AppBackendNamespace,

conformance/tests/gateway_following_epp_routing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
6363

6464
t.Log("Verifying HTTPRoute and InferencePool are accepted and the Gateway has an address.")
6565
k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, httpRouteNN, gatewayNN)
66-
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN)
66+
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewayNN)
6767
gwAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, gatewayNN)
6868

6969
t.Logf("Fetching backend pods with labels: %v", backendPodLabels)

conformance/tests/inferencepool_accepted.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ var InferencePoolAccepted = suite.ConformanceTest{
4343
},
4444
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
4545
poolNN := resources.PrimaryInferencePoolNN
46+
gatewayNN := resources.PrimaryGatewayNN
4647

4748
t.Run("InferencePool should have Accepted condition set to True", func(t *testing.T) {
4849
acceptedCondition := metav1.Condition{
4950
Type: string(gatewayv1.GatewayConditionAccepted),
5051
Status: metav1.ConditionTrue,
5152
Reason: "", // "" means we don't strictly check the Reason for this basic test.
5253
}
53-
k8sutils.InferencePoolMustHaveCondition(t, s.Client, poolNN, acceptedCondition)
54+
k8sutils.InferencePoolMustHaveCondition(t, s.Client, poolNN, gatewayNN, acceptedCondition)
5455
})
5556
},
5657
}

conformance/tests/inferencepool_httproute_port_validation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var InferencePoolHTTPRoutePortValidation = suite.ConformanceTest{
5252
path := "/test-port-unspecified"
5353

5454
k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN)
55-
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN)
55+
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewayNN)
5656

5757
trafficutils.MakeRequestAndExpectSuccess(
5858
t,
@@ -74,7 +74,7 @@ var InferencePoolHTTPRoutePortValidation = suite.ConformanceTest{
7474
path := "/test-port-matching"
7575

7676
k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN)
77-
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN)
77+
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewayNN)
7878

7979
trafficutils.MakeRequestAndExpectSuccess(
8080
t,
@@ -97,7 +97,7 @@ var InferencePoolHTTPRoutePortValidation = suite.ConformanceTest{
9797
path := "/test-port-non-matching"
9898

9999
k8sutils.HTTPRouteMustBeAcceptedAndResolved(t, s.Client, s.TimeoutConfig, routeNN, gatewayNN)
100-
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN)
100+
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewayNN)
101101

102102
trafficutils.MakeRequestAndExpectSuccess(
103103
t,

conformance/tests/inferencepool_invalid_epp_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var InferencePoolInvalidEPPService = suite.ConformanceTest{
6565
Status: metav1.ConditionFalse,
6666
Reason: "", // "" means we don't strictly check the Reason for this basic test.
6767
}
68-
k8sutils.InferencePoolMustHaveCondition(t, s.Client, poolNN, acceptedCondition)
68+
k8sutils.InferencePoolMustHaveCondition(t, s.Client, poolNN, gwNN, acceptedCondition)
6969
})
7070

7171
t.Run("Request to a route with an invalid backend reference receives a 500 response", func(t *testing.T) {

conformance/tests/inferencepool_resolvedrefs_condition.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ var InferencePoolParentStatus = suite.ConformanceTest{
7272
gwSecondaryAddr := k8sutils.GetGatewayEndpoint(t, s.Client, s.TimeoutConfig, gatewaySecondaryNN)
7373

7474
t.Run("InferencePool should show Accepted:True by parents and be routable via multiple HTTPRoutes", func(t *testing.T) {
75-
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN)
75+
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewayPrimaryNN)
76+
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewaySecondaryNN)
7677
t.Logf("InferencePool %s has parent status Accepted:True as expected with two references.", poolNN.String())
7778

7879
trafficutils.MakeRequestAndExpectSuccess(
@@ -112,7 +113,7 @@ var InferencePoolParentStatus = suite.ConformanceTest{
112113
t.Logf("Waiting for %v for Gateway conditions to update after deleting HTTPRoute %s", inferenceTimeoutConfig.HTTPRouteDeletionReconciliationTimeout, httpRoutePrimaryNN.String())
113114
time.Sleep(inferenceTimeoutConfig.HTTPRouteDeletionReconciliationTimeout)
114115

115-
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN)
116+
k8sutils.InferencePoolMustBeAcceptedByParent(t, s.Client, poolNN, gatewaySecondaryNN)
116117
t.Logf("InferencePool %s still has parent status Accepted:True as expected with one reference remaining.", poolNN.String())
117118

118119
trafficutils.MakeRequestAndExpectSuccess(

conformance/utils/kubernetes/helpers.go

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func checkCondition(t *testing.T, conditions []metav1.Condition, expectedConditi
6969
// InferencePoolMustHaveCondition waits for the specified InferencePool resource
7070
// to exist and report the expected status condition within one of its parent statuses.
7171
// It polls the InferencePool's status until the condition is met or the timeout occurs.
72-
func InferencePoolMustHaveCondition(t *testing.T, c client.Reader, poolNN types.NamespacedName, expectedCondition metav1.Condition) {
72+
func InferencePoolMustHaveCondition(t *testing.T, c client.Reader, poolNN types.NamespacedName, gateway types.NamespacedName, expectedCondition metav1.Condition) {
7373
t.Helper() // Marks this function as a test helper
7474

7575
var timeoutConfig = config.DefaultInferenceExtensionTimeoutConfig()
@@ -104,9 +104,11 @@ func InferencePoolMustHaveCondition(t *testing.T, c client.Reader, poolNN types.
104104
}
105105

106106
for _, parentStatus := range pool.Status.Parents {
107-
if checkCondition(t, parentStatus.Conditions, expectedCondition) {
108-
conditionFound = true
109-
return true, nil
107+
if parentStatus.GatewayRef.Namespace != nil && string(*parentStatus.GatewayRef.Namespace) == gateway.Namespace && string(parentStatus.GatewayRef.Name) == gateway.Name {
108+
if checkCondition(t, parentStatus.Conditions, expectedCondition) {
109+
conditionFound = true
110+
return true, nil
111+
}
110112
}
111113
}
112114
return false, nil
@@ -242,8 +244,8 @@ func HTTPRouteMustBeAcceptedAndResolved(t *testing.T, c client.Client, timeoutCo
242244

243245
// InferencePoolMustBeAcceptedByParent waits for the specified InferencePool
244246
// to report an Accepted condition with status True and reason "Accepted"
245-
// from at least one of its parent Gateways.
246-
func InferencePoolMustBeAcceptedByParent(t *testing.T, c client.Reader, poolNN types.NamespacedName) {
247+
// from the input Gateway.
248+
func InferencePoolMustBeAcceptedByParent(t *testing.T, c client.Reader, poolNN, gatewayNN types.NamespacedName) {
247249
t.Helper()
248250

249251
acceptedByParentCondition := metav1.Condition{
@@ -253,28 +255,10 @@ func InferencePoolMustBeAcceptedByParent(t *testing.T, c client.Reader, poolNN t
253255
}
254256

255257
t.Logf("Waiting for InferencePool %s to be Accepted by a parent Gateway (Reason: %s)", poolNN.String(), gatewayv1.GatewayReasonAccepted)
256-
InferencePoolMustHaveCondition(t, c, poolNN, acceptedByParentCondition)
258+
InferencePoolMustHaveCondition(t, c, poolNN, gatewayNN, acceptedByParentCondition)
257259
t.Logf("InferencePool %s is Accepted by a parent Gateway (Reason: %s)", poolNN.String(), gatewayv1.GatewayReasonAccepted)
258260
}
259261

260-
// InferencePoolMustBeRouteAccepted waits for the specified InferencePool resource
261-
// to exist and report an Accepted condition with Type=RouteConditionAccepted,
262-
// Status=True, and Reason=RouteReasonAccepted within one of its parent statuses.
263-
func InferencePoolMustBeRouteAccepted(t *testing.T, c client.Reader, poolNN types.NamespacedName) {
264-
t.Helper()
265-
266-
expectedPoolCondition := metav1.Condition{
267-
Type: string(gatewayv1.RouteConditionAccepted),
268-
Status: metav1.ConditionTrue,
269-
Reason: string(gatewayv1.RouteReasonAccepted),
270-
}
271-
272-
// Call the existing generic helper with the predefined condition
273-
InferencePoolMustHaveCondition(t, c, poolNN, expectedPoolCondition)
274-
t.Logf("InferencePool %s successfully verified with RouteAccepted condition (Type: %s, Status: %s, Reason: %s).",
275-
poolNN.String(), expectedPoolCondition.Type, expectedPoolCondition.Status, expectedPoolCondition.Reason)
276-
}
277-
278262
// HTTPRouteAndInferencePoolMustBeAcceptedAndRouteAccepted waits for the specified HTTPRoute
279263
// to be Accepted and have its references resolved by the specified Gateway,
280264
// AND for the specified InferencePool to be "RouteAccepted" using the specific
@@ -289,7 +273,7 @@ func HTTPRouteAndInferencePoolMustBeAcceptedAndRouteAccepted(
289273
var timeoutConfig = config.DefaultInferenceExtensionTimeoutConfig()
290274

291275
HTTPRouteMustBeAcceptedAndResolved(t, c, timeoutConfig.TimeoutConfig, routeNN, gatewayNN)
292-
InferencePoolMustBeRouteAccepted(t, c, poolNN)
276+
InferencePoolMustBeAcceptedByParent(t, c, poolNN, gatewayNN)
293277
t.Logf("Successfully verified: HTTPRoute %s (Gateway %s) is Accepted & Resolved, and InferencePool %s is RouteAccepted.",
294278
routeNN.String(), gatewayNN.String(), poolNN.String())
295279
}

0 commit comments

Comments
 (0)