From 6f426cfd2798ea757daf057201543fec59fcee3c Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Mon, 22 Apr 2024 12:00:05 +0200 Subject: [PATCH] Restore lastTransitionTime of ReadyCondition We placed the RestoreLastTransitionTimes before we decide if the ReadyCondition needs to be set to True or not. This causes that the lastTransitionTime of the ReadyCondition changes even if nothing is actually changed during the reconciliation. The OpenStackControlPlane and OpenStackVersion resources watching each other creating a reconcile loop. This change moves the RestoreLastTransitionTimes to happen after the ReadyCondition status is finally set. --- controllers/core/openstackcontrolplane_controller.go | 3 ++- controllers/core/openstackversion_controller.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/core/openstackcontrolplane_controller.go b/controllers/core/openstackcontrolplane_controller.go index b9f40be84..441f86d54 100644 --- a/controllers/core/openstackcontrolplane_controller.go +++ b/controllers/core/openstackcontrolplane_controller.go @@ -160,7 +160,6 @@ func (r *OpenStackControlPlaneReconciler) Reconcile(ctx context.Context, req ctr // Always patch the instance status when exiting this function so we can persist any changes. defer func() { - condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions) // update the Ready condition based on the sub conditions if instance.Status.Conditions.AllSubConditionIsTrue() { instance.Status.Conditions.MarkTrue( @@ -174,6 +173,8 @@ func (r *OpenStackControlPlaneReconciler) Reconcile(ctx context.Context, req ctr instance.Status.Conditions.Mirror(condition.ReadyCondition)) } + condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions) + err := helper.PatchInstance(ctx, instance) if err != nil { _err = err diff --git a/controllers/core/openstackversion_controller.go b/controllers/core/openstackversion_controller.go index c89275f24..c040ad867 100644 --- a/controllers/core/openstackversion_controller.go +++ b/controllers/core/openstackversion_controller.go @@ -128,8 +128,6 @@ func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req // Always patch the instance status when exiting this function so we can persist any changes. defer func() { - condition.RestoreLastTransitionTimes( - &instance.Status.Conditions, savedConditions) // update the Ready condition based on the sub conditions if instance.Status.Conditions.AllSubConditionIsTrue() { instance.Status.Conditions.MarkTrue( @@ -143,6 +141,9 @@ func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req instance.Status.Conditions.Mirror(condition.ReadyCondition)) } + condition.RestoreLastTransitionTimes( + &instance.Status.Conditions, savedConditions) + err := versionHelper.PatchInstance(ctx, instance) if err != nil { _err = err