@@ -77,11 +77,26 @@ func GWCMustHaveAcceptedConditionTrue(t *testing.T, c client.Client, timeoutConf
7777 return gwcMustBeAccepted (t , c , timeoutConfig , gwcName , string (metav1 .ConditionTrue ))
7878}
7979
80+ // GWCMustHaveSupportedVersionConditionTrue waits until the specified GatewayClass has a SupportedVersion condition set with a status value equal to True.
81+ func GWCMustHaveSupportedVersionConditionTrue (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , gwcName string ) string {
82+ return gwcMustBeSupportedVersion (t , c , timeoutConfig , gwcName , string (metav1 .ConditionTrue ))
83+ }
84+
85+ // GWCMustHaveSupportedVersionConditionFalse waits until the specified GatewayClass has a SupportedVersion condition set with a status value equal to False.
86+ func GWCMustHaveSupportedVersionConditionFalse (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , gwcName string ) string {
87+ return gwcMustBeSupportedVersion (t , c , timeoutConfig , gwcName , string (metav1 .ConditionFalse ))
88+ }
89+
8090// GWCMustHaveAcceptedConditionAny waits until the specified GatewayClass has an Accepted condition set with a status set to any value.
8191func GWCMustHaveAcceptedConditionAny (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , gwcName string ) string {
8292 return gwcMustBeAccepted (t , c , timeoutConfig , gwcName , "" )
8393}
8494
95+ // GWCMustHaveSupportedVersionConditionAny waits until the specified GatewayClass has a SupportedVersion condition set to any value.
96+ func GWCMustHaveSupportedVersionConditionAny (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , gwcName string ) string {
97+ return gwcMustBeSupportedVersion (t , c , timeoutConfig , gwcName , "" )
98+ }
99+
85100// gwcMustBeAccepted waits until the specified GatewayClass has an Accepted
86101// condition set. Passing an empty status string means that any value
87102// will be accepted. It also returns the ControllerName for the GatewayClass.
@@ -112,6 +127,35 @@ func gwcMustBeAccepted(t *testing.T, c client.Client, timeoutConfig config.Timeo
112127 return controllerName
113128}
114129
130+ // gwcMustBeSupportedVersion waits until the specified GatewayClass has a SupportedVersion condition set.
131+ // Passing an empty status string means that any value will be accepted. It also returns the ControllerName
132+ // for the GatewayClass. This will cause the test to halt if the specified timeout is exceeded.
133+ func gwcMustBeSupportedVersion (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , gwcName , expectedStatus string ) string {
134+ t .Helper ()
135+
136+ var controllerName string
137+ waitErr := wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , timeoutConfig .GWCMustBeSupportedVersion , true , func (ctx context.Context ) (bool , error ) {
138+ gwc := & gatewayv1.GatewayClass {}
139+ err := c .Get (ctx , types.NamespacedName {Name : gwcName }, gwc )
140+ if err != nil {
141+ return false , fmt .Errorf ("error fetching GatewayClass: %w" , err )
142+ }
143+
144+ controllerName = string (gwc .Spec .ControllerName )
145+
146+ if err := ConditionsHaveLatestObservedGeneration (gwc , gwc .Status .Conditions ); err != nil {
147+ tlog .Log (t , "GatewayClass" , err )
148+ return false , nil
149+ }
150+
151+ // Passing an empty string as the Reason means that any Reason will do.
152+ return findConditionInList (t , gwc .Status .Conditions , "SupportedVersion" , expectedStatus , "" ), nil
153+ })
154+ require .NoErrorf (t , waitErr , "error waiting for %s GatewayClass to have SupportedVersion condition to be set: %v" , gwcName , waitErr )
155+
156+ return controllerName
157+ }
158+
115159// GatewayMustHaveLatestConditions waits until the specified Gateway has
116160// all conditions updated with the latest observed generation.
117161func GatewayMustHaveLatestConditions (t * testing.T , c client.Client , timeoutConfig config.TimeoutConfig , gwNN types.NamespacedName ) {
@@ -249,6 +293,52 @@ func NamespacesMustBeReady(t *testing.T, c client.Client, timeoutConfig config.T
249293 require .NoErrorf (t , waitErr , "error waiting for %s namespaces to be ready" , strings .Join (namespaces , ", " ))
250294}
251295
296+ // GatewayClassMustHaveCondition checks that the supplied GatewayClass has the supplied Condition,
297+ // halting after the specified timeout is exceeded.
298+ func GatewayClassMustHaveCondition (
299+ t * testing.T ,
300+ client client.Client ,
301+ timeoutConfig config.TimeoutConfig ,
302+ gcName string ,
303+ expectedCondition metav1.Condition ,
304+ ) {
305+ t .Helper ()
306+
307+ waitErr := wait .PollUntilContextTimeout (
308+ context .Background (),
309+ 1 * time .Second ,
310+ timeoutConfig .GWCMustBeSupportedVersion ,
311+ true ,
312+ func (ctx context.Context ) (bool , error ) {
313+ gc := & gatewayv1.GatewayClass {}
314+ gcNN := types.NamespacedName {
315+ Name : gcName ,
316+ }
317+ err := client .Get (ctx , gcNN , gc )
318+ if err != nil {
319+ return false , fmt .Errorf ("error fetching GatewayClass: %w" , err )
320+ }
321+
322+ if err := ConditionsHaveLatestObservedGeneration (gc , gc .Status .Conditions ); err != nil {
323+ return false , err
324+ }
325+
326+ if findConditionInList (t ,
327+ gc .Status .Conditions ,
328+ expectedCondition .Type ,
329+ string (expectedCondition .Status ),
330+ expectedCondition .Reason ,
331+ ) {
332+ return true , nil
333+ }
334+
335+ return false , nil
336+ },
337+ )
338+
339+ require .NoErrorf (t , waitErr , "error waiting for GatewayClass status to have a Condition matching expectations" )
340+ }
341+
252342// GatewayMustHaveCondition checks that the supplied Gateway has the supplied Condition,
253343// halting after the specified timeout is exceeded.
254344func GatewayMustHaveCondition (
0 commit comments