Skip to content

Commit

Permalink
report gateway status
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain committed Jan 16, 2025
1 parent b84b291 commit 6306c93
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 69 deletions.
25 changes: 8 additions & 17 deletions internal/gatewayapi/status/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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"
Expand Down
39 changes: 0 additions & 39 deletions internal/gatewayapi/status/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
10 changes: 0 additions & 10 deletions internal/infrastructure/kubernetes/infra_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,12 @@ func (r *gatewayAPIReconciler) processGateways(ctx context.Context, managedGC *g

if err := r.processGatewayParamsRef(ctx, &gtw, resourceMap, resourceTree); err != nil {
r.log.Error(err, "failed to process infrastructure.parametersRef for gateway", "namespace", gtw.Namespace, "name", gtw.Name)
status.SetGatewayAccepted(&gtw, false, gwapiv1.GatewayReasonInvalidParameters, err.Error())
r.updateGatewayStatus(&gtw)
continue
}
status.SetGatewayAccepted(&gtw, false, gwapiv1.GatewayReasonAccepted, "The Gateway has not been scheduled by Envoy Gateway")
r.updateGatewayStatus(&gtw)

for _, listener := range gtw.Spec.Listeners {
// Get Secret for gateway if it exists.
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/kubernetes/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions internal/provider/kubernetes/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()...)

Expand Down

0 comments on commit 6306c93

Please sign in to comment.