Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e8034a3

Browse files
committedSep 28, 2023
Check gateway positive-polarity conditions
1 parent d3b272e commit e8034a3

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed
 

‎conformance/utils/kubernetes/helpers.go

+52-27
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"reflect"
2525
"strconv"
2626
"strings"
27+
"sync"
2728
"testing"
2829
"time"
2930

@@ -268,12 +269,14 @@ func MeshNamespacesMustBeReady(t *testing.T, c client.Client, timeoutConfig conf
268269
}
269270

270271
// GatewayAndHTTPRoutesMustBeAccepted waits until:
271-
// 1. The specified Gateway has an IP address assigned to it.
272-
// 2. The route has a ParentRef referring to the Gateway.
273-
// 3. All the gateway's listeners have the ListenerConditionResolvedRefs set to true.
272+
// 1. The specified Gateway has an IP address assigned to it.
273+
// 2. The route has a ParentRef referring to the Gateway.
274+
// 3. All the gateway's listeners have the following conditions set to true:
275+
// - ListenerConditionResolvedRefs
276+
// - ListenerConditionAccepted
277+
// - ListenerConditionProgrammed
274278
//
275-
// The test will fail if these conditions are not met before the
276-
// timeouts.
279+
// The test will fail if these conditions are not met before the timeouts.
277280
func GatewayAndHTTPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutConfig config.TimeoutConfig, controllerName string, gw GatewayRef, routeNNs ...types.NamespacedName) string {
278281
t.Helper()
279282

@@ -310,13 +313,24 @@ func GatewayAndHTTPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutCo
310313
HTTPRouteMustHaveParents(t, c, timeoutConfig, routeNN, parents, namespaceRequired)
311314
}
312315

313-
resolvedRefsCondition := metav1.Condition{
314-
Type: string(v1beta1.ListenerConditionResolvedRefs),
315-
Status: metav1.ConditionTrue,
316-
Reason: "", // any reason
316+
requiredListenerConditions := []metav1.Condition{
317+
{
318+
Type: string(v1beta1.ListenerConditionResolvedRefs),
319+
Status: metav1.ConditionTrue,
320+
Reason: "", // any reason
321+
},
322+
{
323+
Type: string(v1beta1.ListenerConditionAccepted),
324+
Status: metav1.ConditionTrue,
325+
Reason: "", // any reason
326+
},
327+
{
328+
Type: string(v1beta1.ListenerConditionProgrammed),
329+
Status: metav1.ConditionTrue,
330+
Reason: "", // any reason
331+
},
317332
}
318-
319-
GatewayListenersMustHaveCondition(t, c, timeoutConfig, gw.NamespacedName, resolvedRefsCondition)
333+
GatewayListenersMustHaveConditions(t, c, timeoutConfig, gw.NamespacedName, requiredListenerConditions)
320334

321335
return gwAddr
322336
}
@@ -356,27 +370,38 @@ func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig con
356370
return net.JoinHostPort(ipAddr, port), waitErr
357371
}
358372

359-
// GatewayListenersMustHaveCondition checks if every listener of the specified gateway has a
360-
// certain condition.
361-
func GatewayListenersMustHaveCondition(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, gwName types.NamespacedName, condition metav1.Condition) {
373+
// GatewayListenersMustHaveConditions checks if every listener of the specified gateway has all
374+
// the specified conditions.
375+
func GatewayListenersMustHaveConditions(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, gwName types.NamespacedName, conditions []metav1.Condition) {
362376
t.Helper()
363377

364-
waitErr := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, timeoutConfig.GatewayListenersMustHaveCondition, true, func(ctx context.Context) (bool, error) {
365-
var gw v1beta1.Gateway
366-
if err := client.Get(ctx, gwName, &gw); err != nil {
367-
return false, fmt.Errorf("error fetching Gateway: %w", err)
368-
}
378+
var wg sync.WaitGroup
379+
wg.Add(len(conditions))
369380

370-
for _, listener := range gw.Status.Listeners {
371-
if !findConditionInList(t, listener.Conditions, condition.Type, string(condition.Status), condition.Reason) {
372-
return false, nil
373-
}
374-
}
381+
for _, condition := range conditions {
382+
go func(condition metav1.Condition) {
383+
defer wg.Done()
375384

376-
return true, nil
377-
})
385+
waitErr := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, timeoutConfig.GatewayListenersMustHaveCondition, true, func(ctx context.Context) (bool, error) {
386+
var gw v1beta1.Gateway
387+
if err := client.Get(ctx, gwName, &gw); err != nil {
388+
return false, fmt.Errorf("error fetching Gateway: %w", err)
389+
}
390+
391+
for _, listener := range gw.Status.Listeners {
392+
if !findConditionInList(t, listener.Conditions, condition.Type, string(condition.Status), condition.Reason) {
393+
return false, nil
394+
}
395+
}
396+
397+
return true, nil
398+
})
399+
400+
require.NoErrorf(t, waitErr, "error waiting for Gateway status to have a Condition matching expectations on all listeners")
401+
}(condition)
402+
}
378403

379-
require.NoErrorf(t, waitErr, "error waiting for Gateway status to have a Condition matching expectations on all listeners")
404+
wg.Wait()
380405
}
381406

382407
// GatewayMustHaveZeroRoutes validates that the gateway has zero routes attached. The status

0 commit comments

Comments
 (0)
Failed to load comments.