@@ -19,6 +19,7 @@ import (
1919 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020 "k8s.io/apimachinery/pkg/types"
2121 "k8s.io/apimachinery/pkg/util/intstr"
22+ apiwatch "k8s.io/apimachinery/pkg/watch"
2223 "sigs.k8s.io/controller-runtime/pkg/client"
2324 gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2425
@@ -27,6 +28,7 @@ import (
2728 operatorv2beta1 "github.com/kong/kong-operator/api/gateway-operator/v2beta1"
2829 konnectv1alpha1 "github.com/kong/kong-operator/api/konnect/v1alpha1"
2930 konnectv1alpha2 "github.com/kong/kong-operator/api/konnect/v1alpha2"
31+ "github.com/kong/kong-operator/modules/manager/scheme"
3032 "github.com/kong/kong-operator/pkg/consts"
3133 "github.com/kong/kong-operator/pkg/gatewayapi"
3234 gatewayutils "github.com/kong/kong-operator/pkg/utils/gateway"
@@ -48,6 +50,14 @@ func TestGatewayEssentials(t *testing.T) {
4850 require .NoError (t , err )
4951 cleaner .Add (gatewayClass )
5052
53+ t .Log ("setting up watch for Gateways" )
54+ cl , err := client .NewWithWatch (GetEnv ().Cluster ().Config (), client.Options {
55+ Scheme : scheme .Get (),
56+ })
57+ require .NoError (t , err , "failed to setup a client for watching gateways" )
58+ wGateway , err := cl .Watch (GetCtx (), & gatewayv1.GatewayList {}, client .InNamespace (namespace .Name ))
59+ require .NoError (t , err , "failed to start watching gateways" )
60+
5161 t .Log ("deploying Gateway resource" )
5262 gatewayNN := types.NamespacedName {
5363 Name : uuid .NewString (),
@@ -110,9 +120,16 @@ func TestGatewayEssentials(t *testing.T) {
110120 t .Log ("deleting dataplane" )
111121 require .NoError (t , dataplaneClient .Delete (GetCtx (), dataplane .Name , metav1.DeleteOptions {}))
112122
113- t .Log ("verifying Gateway gets and its listeners are marked as not Programmed" )
114- require .Eventually (t , testutils .Not (testutils .GatewayIsProgrammed (t , GetCtx (), gatewayNN , clients )), testutils .GatewayReadyTimeLimit , 100 * time .Millisecond )
115- require .Eventually (t , testutils .Not (testutils .GatewayListenersAreProgrammed (t , GetCtx (), gatewayNN , clients )), testutils .GatewayReadyTimeLimit , 100 * time .Millisecond )
123+ t .Logf ("verifying Gateway gets and its listeners are marked as not Programmed at %v" , time .Now ())
124+ _ = helpers .WatchFor (t , GetCtx (), wGateway , apiwatch .Modified ,
125+ testutils .GatewayReadyTimeLimit ,
126+ func (gw * gatewayv1.Gateway ) bool {
127+ return gw .Name == gatewayNN .Name && gw .Namespace == gatewayNN .Namespace &&
128+ ! gatewayutils .IsProgrammed (gw ) && ! gatewayutils .AreListenersProgrammed (gw )
129+ },
130+ "Did not see gateway and all its listeners' Programmed condition set to False" ,
131+ )
132+ t .Logf ("see gateway and all its listeners marked as not programmed at %v in watch" , time .Now ())
116133
117134 t .Log ("verifying that the ControlPlane becomes provisioned again" )
118135 require .Eventually (t , testutils .GatewayControlPlaneIsProvisioned (t , GetCtx (), gateway , clients ), 45 * time .Second , time .Second )
0 commit comments