Skip to content

Commit

Permalink
Update EGW status only if it has changed. (#3577)
Browse files Browse the repository at this point in the history
* Update EGW status only if it has changed.
  • Loading branch information
sridhartigera authored Oct 30, 2024
1 parent 0e1c5a6 commit 2c64f3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
27 changes: 11 additions & 16 deletions pkg/controller/egressgateway/egressgateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,6 @@ func (r *ReconcileEgressGateway) reconcileEgressGateway(ctx context.Context, egw
return err
}

// Set the condition to progressing
setProgressing(r.client, ctx, egw, string(operatorv1.ResourceNotReady), "Reconciling")

egwVXLANPort := egressgateway.DefaultVXLANPort
egwVXLANVNI := egressgateway.DefaultVXLANVNI
if fc.Spec.EgressIPVXLANPort != nil {
Expand Down Expand Up @@ -652,25 +649,25 @@ func getUnreadyEgressGateway(egws []operatorv1.EgressGateway) *operatorv1.Egress

// setDegraded updates the degraded status condition of the EGW resource.
func setDegraded(cli client.Client, ctx context.Context, egw *operatorv1.EgressGateway, reason, msg string) {
updateEGWStatusConditions(cli, ctx, egw, operatorv1.ComponentDegraded, metav1.ConditionTrue, reason, msg, true)
}

// setProgressing updates the progressing status condition of the EGW resource.
func setProgressing(cli client.Client, ctx context.Context, egw *operatorv1.EgressGateway, reason, msg string) {
updateEGWStatusConditions(cli, ctx, egw, operatorv1.ComponentProgressing, metav1.ConditionTrue, reason, msg, false)
updateEGWStatusConditions(cli, ctx, egw, operatorv1.ComponentDegraded, metav1.ConditionTrue, reason, msg)
}

// setProgressing updates the ready status condition of the EGW resource.
// setAvailable updates the ready status condition of the EGW resource.
func setAvailable(cli client.Client, ctx context.Context, egw *operatorv1.EgressGateway, reason, msg string) {
updateEGWStatusConditions(cli, ctx, egw, operatorv1.ComponentAvailable, metav1.ConditionTrue, reason, msg, true)
updateEGWStatusConditions(cli, ctx, egw, operatorv1.ComponentAvailable, metav1.ConditionTrue, reason, msg)
}

// updateEGWStatusConditions sets the status conditions of the EGW resource and if updateStatus is True, status of the EGW resource
// is updated in the datastore.
func updateEGWStatusConditions(cli client.Client, ctx context.Context, egw *operatorv1.EgressGateway, ctype operatorv1.StatusConditionType, status metav1.ConditionStatus, reason, msg string, updateStatus bool) {
func updateEGWStatusConditions(cli client.Client, ctx context.Context, egw *operatorv1.EgressGateway, ctype operatorv1.StatusConditionType, status metav1.ConditionStatus, reason, msg string) {
found := false
for idx, cond := range egw.Status.Conditions {
if cond.Type == string(ctype) {
if cond.Status == status &&
cond.Reason == reason &&
cond.Message == msg {
return
}
cond.Status = status
cond.Reason = reason
cond.Message = msg
Expand All @@ -687,10 +684,8 @@ func updateEGWStatusConditions(cli client.Client, ctx context.Context, egw *oper
condition := metav1.Condition{Type: string(ctype), Status: status, Reason: reason, Message: msg, LastTransitionTime: metav1.NewTime(time.Now())}
egw.Status.Conditions = append(egw.Status.Conditions, condition)
}
if updateStatus {
if err := cli.Status().Update(ctx, egw); err != nil {
log.WithValues("Name", egw.Name, "Namespace", egw.Namespace, "error", err).Info("Error updating status")
}
if err := cli.Status().Update(ctx, egw); err != nil {
log.WithValues("Name", egw.Name, "Namespace", egw.Namespace, "error", err).Info("Error updating status")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,10 @@ spec:
description: 'WireguardRoutingRulePriority controls the priority value
to use for the Wireguard routing rule. [Default: 99]'
type: integer
wireguardThreadingEnabled:
description: 'WireguardThreadingEnabled controls whether Wireguard
has NAPI threading enabled. [Default: false]'
type: boolean
workloadSourceSpoofing:
description: WorkloadSourceSpoofing controls whether pods can use
the allowedSourcePrefixes annotation to send traffic with a source
Expand Down

0 comments on commit 2c64f3a

Please sign in to comment.