diff --git a/internal/gatewayapi/status/gateway.go b/internal/gatewayapi/status/gateway.go index 8bf822479d0..4b8d977024e 100644 --- a/internal/gatewayapi/status/gateway.go +++ b/internal/gatewayapi/status/gateway.go @@ -23,9 +23,14 @@ func UpdateGatewayListenersNotValidCondition(gw *gwapiv1.Gateway, reason gwapiv1 return gw } -// UpdateGatewayStatusAcceptedCondition updates the status condition for the provided Gateway based on the accepted state. -func UpdateGatewayStatusAcceptedCondition(gw *gwapiv1.Gateway, accepted bool) *gwapiv1.Gateway { - gw.Status.Conditions = MergeConditions(gw.Status.Conditions, computeGatewayAcceptedCondition(gw, accepted)) +// SetGatewayAccepted set the status condition for the provided Gateway based on the accepted state. +func SetGatewayAccepted(gw *gwapiv1.Gateway, accepted bool, reason gwapiv1.GatewayConditionReason, message string) *gwapiv1.Gateway { + status := metav1.ConditionFalse + if accepted { + status = metav1.ConditionTrue + } + cond := newCondition(string(gwapiv1.GatewayReasonAccepted), status, string(reason), message, time.Now(), gw.Generation) + gw.Status.Conditions = MergeConditions(gw.Status.Conditions, cond) return gw } @@ -116,20 +121,6 @@ func SetGatewayListenerStatusCondition(gateway *gwapiv1.Gateway, listenerStatusI gateway.Status.Listeners[listenerStatusIdx].Conditions = MergeConditions(gateway.Status.Listeners[listenerStatusIdx].Conditions, cond) } -// computeGatewayAcceptedCondition computes the Gateway Accepted status condition. -func computeGatewayAcceptedCondition(gw *gwapiv1.Gateway, accepted bool) metav1.Condition { - switch accepted { - case true: - return newCondition(string(gwapiv1.GatewayReasonAccepted), metav1.ConditionTrue, - string(gwapiv1.GatewayReasonAccepted), - "The Gateway has been scheduled by Envoy Gateway", time.Now(), gw.Generation) - default: - return newCondition(string(gwapiv1.GatewayReasonAccepted), metav1.ConditionFalse, - string(gwapiv1.GatewayReasonAccepted), - "The Gateway has not been scheduled by Envoy Gateway", time.Now(), gw.Generation) - } -} - const ( messageAddressNotAssigned = "No addresses have been assigned to the Gateway" messageFmtTooManyAddresses = "Too many addresses (%d) have been assigned to the Gateway, the maximum number of addresses is 16" diff --git a/internal/gatewayapi/status/gateway_test.go b/internal/gatewayapi/status/gateway_test.go index 9f9791ac6a5..c2d18a7fc15 100644 --- a/internal/gatewayapi/status/gateway_test.go +++ b/internal/gatewayapi/status/gateway_test.go @@ -334,42 +334,3 @@ func TestUpdateGatewayProgrammedCondition(t *testing.T) { }) } } - -func TestComputeGatewayScheduledCondition(t *testing.T) { - testCases := []struct { - name string - sched bool - expect metav1.Condition - }{ - { - name: "scheduled gateway", - sched: true, - expect: metav1.Condition{ - Type: string(gwapiv1.GatewayReasonAccepted), - Status: metav1.ConditionTrue, - }, - }, - { - name: "not scheduled gateway", - sched: false, - expect: metav1.Condition{ - Type: string(gwapiv1.GatewayReasonAccepted), - Status: metav1.ConditionFalse, - }, - }, - } - - for _, tc := range testCases { - gw := &gwapiv1.Gateway{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "test", - Name: "test", - }, - } - - got := computeGatewayAcceptedCondition(gw, tc.sched) - - assert.Equal(t, tc.expect.Type, got.Type) - assert.Equal(t, tc.expect.Status, got.Status) - } -} diff --git a/internal/infrastructure/kubernetes/infra_resource.go b/internal/infrastructure/kubernetes/infra_resource.go index 1bec17c0903..a5f4dc50576 100644 --- a/internal/infrastructure/kubernetes/infra_resource.go +++ b/internal/infrastructure/kubernetes/infra_resource.go @@ -406,11 +406,6 @@ func (i *Infra) deleteServiceAccount(ctx context.Context, r ResourceRender) (err // deleteDeployment deletes the Envoy Deployment in the kube api server, if it exists. func (i *Infra) deleteDeployment(ctx context.Context, r ResourceRender) (err error) { - // If deployment config is nil,ignore Deployment. - if deploymentConfig, er := r.DeploymentSpec(); deploymentConfig == nil { - return er - } - var ( name, ns = r.Name(), i.Namespace deployment = &appsv1.Deployment{ @@ -446,11 +441,6 @@ func (i *Infra) deleteDeployment(ctx context.Context, r ResourceRender) (err err // deleteDaemonSet deletes the Envoy DaemonSet in the kube api server, if it exists. func (i *Infra) deleteDaemonSet(ctx context.Context, r ResourceRender) (err error) { - // If daemonset config is nil, ignore DaemonSet. - if daemonSetConfig, er := r.DaemonSetSpec(); daemonSetConfig == nil { - return er - } - var ( name, ns = r.Name(), i.Namespace daemonSet = &appsv1.DaemonSet{ diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index a6abb5fc72b..d74882eb448 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -938,8 +938,12 @@ func (r *gatewayAPIReconciler) processGateways(ctx context.Context, managedGC *g if err := r.processGatewayParamsRef(ctx, >w, resourceMap, resourceTree); err != nil { r.log.Error(err, "failed to process infrastructure.parametersRef for gateway", "namespace", gtw.Namespace, "name", gtw.Name) + status.SetGatewayAccepted(>w, false, gwapiv1.GatewayReasonInvalidParameters, err.Error()) + r.updateGatewayStatus(>w) continue } + status.SetGatewayAccepted(>w, false, gwapiv1.GatewayReasonAccepted, "The Gateway has not been scheduled by Envoy Gateway") + r.updateGatewayStatus(>w) for _, listener := range gtw.Spec.Listeners { // Get Secret for gateway if it exists. diff --git a/internal/provider/kubernetes/predicates.go b/internal/provider/kubernetes/predicates.go index 16bb9361b04..a93d9b0d1cb 100644 --- a/internal/provider/kubernetes/predicates.go +++ b/internal/provider/kubernetes/predicates.go @@ -654,7 +654,7 @@ func (r *gatewayAPIReconciler) updateGatewayStatus(gateway *gwapiv1.Gateway) { // Since the status does not reflect the actual changed status, we need to delete it first // to prevent it from being considered unchanged. This ensures that subscribers receive the update event. r.resources.GatewayStatuses.Delete(gwName) - // The status that is stored in the GatewayStatuses GatewayStatuses is solely used to trigger the status updater + // The status that is stored in the GatewayStatuses is solely used to trigger the status updater // and does not reflect the real changed status. // // The status updater will check the Envoy Proxy service to get the addresses of the Gateway, diff --git a/internal/provider/kubernetes/status.go b/internal/provider/kubernetes/status.go index d9ff03f9b66..c54813a323d 100644 --- a/internal/provider/kubernetes/status.go +++ b/internal/provider/kubernetes/status.go @@ -568,8 +568,7 @@ func (r *gatewayAPIReconciler) updateStatusForGateway(ctx context.Context, gtw * r.log.Info("failed to get Service for gateway", "namespace", gtw.Namespace, "name", gtw.Name) } - // update accepted condition - status.UpdateGatewayStatusAcceptedCondition(gtw, true) + // update address field and programmed condition status.UpdateGatewayStatusProgrammedCondition(gtw, svc, envoyObj, r.store.listNodeAddresses()...)