Skip to content

Commit

Permalink
Version: Create helper before manipulating instance
Browse files Browse the repository at this point in the history
The helper.NewHelper creates snapshot of the instance being reconciled
and PatchInstance at the end of the reconcile loop uses this to generate
the Patch to persist the changes done by the reconciler. Therefore the
helper needs to be created before any changes on the instance. This is
fixed now to avoid loosing in memory changes.
  • Loading branch information
gibizer committed Apr 25, 2024
1 parent 47fcf16 commit 670e517
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions controllers/core/openstackversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, err
}

isNewInstance := instance.Status.Conditions == nil
if isNewInstance {
instance.Status.Conditions = condition.Conditions{}
}

// Save a copy of the condtions so that we can restore the LastTransitionTime
// when a condition's state doesn't change.
savedConditions := instance.Status.Conditions.DeepCopy()

versionHelper, err := helper.NewHelper(
instance,
r.Client,
Expand All @@ -126,6 +117,15 @@ func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, err
}

isNewInstance := instance.Status.Conditions == nil
if isNewInstance {
instance.Status.Conditions = condition.Conditions{}
}

// Save a copy of the condtions so that we can restore the LastTransitionTime
// when a condition's state doesn't change.
savedConditions := instance.Status.Conditions.DeepCopy()

// Always patch the instance status when exiting this function so we can persist any changes.
defer func() {
// update the Ready condition based on the sub conditions
Expand Down

0 comments on commit 670e517

Please sign in to comment.