From 453ad1143048533fc8d55992043cb0897a16aae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Wed, 8 May 2024 13:09:01 +0200 Subject: [PATCH] chore: remove Gateway's Ready status condition --- controller/gateway/controller.go | 4 ++-- .../gateway/controller_reconciler_utils.go | 22 +++++++++---------- controller/gateway/controller_test.go | 10 ++++----- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/controller/gateway/controller.go b/controller/gateway/controller.go index 5e009abcc..ff380e724 100644 --- a/controller/gateway/controller.go +++ b/controller/gateway/controller.go @@ -147,7 +147,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu gwConditionAware.initListenersStatus() gwConditionAware.setConflicted() gwConditionAware.setAccepted() - gwConditionAware.initReadyAndProgrammed() + gwConditionAware.initProgrammedAndListenersStatus() if err := gwConditionAware.setResolvedRefsAndSupportedKinds(ctx, r.Client); err != nil { return ctrl.Result{}, err } @@ -340,7 +340,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu gatewayConditionsAndListenersAware(&gateway)) } - gwConditionAware.setReadyAndProgrammed() + gwConditionAware.setProgrammedAndListenersConditions() res, err := patch.ApplyGatewayStatusPatchIfNotEmpty(ctx, r.Client, logger, &gateway, oldGateway) if err != nil { return ctrl.Result{}, err diff --git a/controller/gateway/controller_reconciler_utils.go b/controller/gateway/controller_reconciler_utils.go index 6995691fc..5ae5c5334 100644 --- a/controller/gateway/controller_reconciler_utils.go +++ b/controller/gateway/controller_reconciler_utils.go @@ -535,12 +535,11 @@ func supportedRoutesByProtocol() map[gatewayv1.ProtocolType]map[gatewayv1.Kind]s } } -// initReadyAndProgrammed initializes the gateway Programmed and Ready conditions -// by setting the underlying Gateway Programmed and Ready status to false. -// Furthermore, it sets the supportedKinds and initializes the readiness to false with reason -// Pending for each Gateway listener. -func (g *gatewayConditionsAndListenersAwareT) initReadyAndProgrammed() { - k8sutils.InitReady(g) +// initProgrammedAndListenersStatus initializes the gateway Programmed condition +// by setting the underlying Gateway Programmed status to false. +// It also sets the listeners Programmed condition by setting the underlying +// Listener Programmed status to false. +func (g *gatewayConditionsAndListenersAwareT) initProgrammedAndListenersStatus() { k8sutils.InitProgrammed(g) for i := range g.Spec.Listeners { lStatus := listenerConditionsAware(&g.Status.Listeners[i]) @@ -634,12 +633,11 @@ func (g *gatewayConditionsAndListenersAwareT) setConflicted() { } } -// setReadyAndProgrammed sets the gateway Programmed and Ready conditions by -// setting the underlying Gateway Programmed and Ready status to true. -// Furthermore, it sets the supportedKinds and initializes the readiness to true with reason -// Ready or false with reason Invalid for each Gateway listener. -func (g *gatewayConditionsAndListenersAwareT) setReadyAndProgrammed() { - k8sutils.SetReady(g) +// setProgrammedAndListenersConditions sets the gateway Programmed condition by setting the underlying +// Gateway Programmed status to true. +// It also sets the listeners Programmed condition by setting the underlying +// Listener Programmed status to true. +func (g *gatewayConditionsAndListenersAwareT) setProgrammedAndListenersConditions() { k8sutils.SetProgrammed(g) for i := range g.Spec.Listeners { diff --git a/controller/gateway/controller_test.go b/controller/gateway/controller_test.go index bdd5ac897..6e41731fa 100644 --- a/controller/gateway/controller_test.go +++ b/controller/gateway/controller_test.go @@ -181,7 +181,7 @@ func TestGatewayReconciler_Reconcile(t *testing.T) { var currentGateway gwtypes.Gateway require.NoError(t, reconciler.Client.Get(ctx, gatewayReq.NamespacedName, ¤tGateway)) - require.False(t, k8sutils.IsReady(gatewayConditionsAndListenersAware(¤tGateway))) + require.False(t, k8sutils.IsProgrammed(gatewayConditionsAndListenersAware(¤tGateway))) condition, found := k8sutils.GetCondition(GatewayServiceType, gatewayConditionsAndListenersAware(¤tGateway)) require.True(t, found) require.Equal(t, condition.Status, metav1.ConditionFalse) @@ -200,7 +200,7 @@ func TestGatewayReconciler_Reconcile(t *testing.T) { require.NoError(t, err, "reconciliation returned an error") // the dataplane service now has a clusterIP assigned, the gateway must be ready require.NoError(t, reconciler.Client.Get(ctx, gatewayReq.NamespacedName, ¤tGateway)) - require.True(t, k8sutils.IsReady(gatewayConditionsAndListenersAware(¤tGateway))) + require.True(t, k8sutils.IsProgrammed(gatewayConditionsAndListenersAware(¤tGateway))) condition, found = k8sutils.GetCondition(GatewayServiceType, gatewayConditionsAndListenersAware(¤tGateway)) require.True(t, found) require.Equal(t, condition.Status, metav1.ConditionTrue) @@ -234,7 +234,7 @@ func TestGatewayReconciler_Reconcile(t *testing.T) { _, err = reconciler.Reconcile(ctx, gatewayReq) require.NoError(t, err, "reconciliation returned an error") require.NoError(t, reconciler.Client.Get(ctx, gatewayReq.NamespacedName, ¤tGateway)) - require.True(t, k8sutils.IsReady(gatewayConditionsAndListenersAware(¤tGateway))) + require.True(t, k8sutils.IsProgrammed(gatewayConditionsAndListenersAware(¤tGateway))) condition, found = k8sutils.GetCondition(GatewayServiceType, gatewayConditionsAndListenersAware(¤tGateway)) require.True(t, found) require.Equal(t, condition.Status, metav1.ConditionTrue) @@ -267,7 +267,7 @@ func TestGatewayReconciler_Reconcile(t *testing.T) { _, err = reconciler.Reconcile(ctx, gatewayReq) require.NoError(t, err, "reconciliation returned an error") require.NoError(t, reconciler.Client.Get(ctx, gatewayReq.NamespacedName, ¤tGateway)) - require.True(t, k8sutils.IsReady(gatewayConditionsAndListenersAware(¤tGateway))) + require.True(t, k8sutils.IsProgrammed(gatewayConditionsAndListenersAware(¤tGateway))) condition, found = k8sutils.GetCondition(GatewayServiceType, gatewayConditionsAndListenersAware(¤tGateway)) require.True(t, found) require.Equal(t, condition.Status, metav1.ConditionTrue) @@ -289,7 +289,7 @@ func TestGatewayReconciler_Reconcile(t *testing.T) { require.NoError(t, reconciler.Client.Get(ctx, gatewayReq.NamespacedName, ¤tGateway)) // the dataplane service has no clusterIP assigned, the gateway must be not ready // and no addresses must be assigned - require.False(t, k8sutils.IsReady(gatewayConditionsAndListenersAware(¤tGateway))) + require.False(t, k8sutils.IsProgrammed(gatewayConditionsAndListenersAware(¤tGateway))) condition, found = k8sutils.GetCondition(GatewayServiceType, gatewayConditionsAndListenersAware(¤tGateway)) require.True(t, found) require.Equal(t, condition.Status, metav1.ConditionFalse)