Skip to content

Commit

Permalink
refactor: update status after Konnect update
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Oct 7, 2024
1 parent f77dad3 commit a3f201f
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions controller/konnect/reconciler_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,26 +524,20 @@ func (r *KonnectEntityReconciler[T, TEnt]) Reconcile(
return ctrl.Result{}, nil
}

if res, err := ops.Update[T, TEnt](ctx, sdk, r.SyncPeriod, r.Client, ent); err != nil {
ent.GetKonnectStatus().ServerURL = apiAuth.Spec.ServerURL
ent.GetKonnectStatus().OrgID = apiAuth.Status.OrganizationID
if errUpd := r.Client.Status().Update(ctx, ent); errUpd != nil {
if k8serrors.IsConflict(errUpd) {
return ctrl.Result{Requeue: true}, nil
}
return ctrl.Result{}, fmt.Errorf("failed to update in cluster resource after Konnect update: %w %w", errUpd, err)
}

return ctrl.Result{}, fmt.Errorf("failed to update object: %w", err)
} else if !res.IsZero() {
return res, nil
}

if err := r.Client.Status().Update(ctx, ent); err != nil {
if k8serrors.IsConflict(err) {
res, err = ops.Update[T, TEnt](ctx, sdk, r.SyncPeriod, r.Client, ent)
ent.GetKonnectStatus().ServerURL = apiAuth.Spec.ServerURL
ent.GetKonnectStatus().OrgID = apiAuth.Status.OrganizationID
if errUpd := r.Client.Status().Update(ctx, ent); errUpd != nil {
if k8serrors.IsConflict(errUpd) {
return ctrl.Result{Requeue: true}, nil
}
return ctrl.Result{}, fmt.Errorf("failed to update in cluster resource after Konnect update: %w", err)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update in cluster resource after Konnect update has failed: %w %w", errUpd, err)
}
return ctrl.Result{}, fmt.Errorf("failed to update in cluster resource after Konnect update: %w", errUpd)
}
if !res.IsZero() {
return res, nil
}

// NOTE: We requeue here to keep enforcing the state of the resource in Konnect.
Expand Down

0 comments on commit a3f201f

Please sign in to comment.