From e4a5e251686ba47c7f64241ece9aa105e2e790f9 Mon Sep 17 00:00:00 2001 From: Alan Bishop Date: Fri, 29 Mar 2024 13:26:07 -0700 Subject: [PATCH] Mirror ReadyCondition with the actual current condition Initialize the ReadyCondition to Unknown, and in the controller's defer function mirror the latest current condition. The updates the ReadyCondition with information about whatever condition is not yet ready. --- controllers/cinder_controller.go | 7 +++++-- controllers/cinderapi_controller.go | 5 +++++ controllers/cinderbackup_controller.go | 5 +++++ controllers/cinderscheduler_controller.go | 5 +++++ controllers/cindervolume_controller.go | 5 +++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/controllers/cinder_controller.go b/controllers/cinder_controller.go index f919522b..864da9e1 100644 --- a/controllers/cinder_controller.go +++ b/controllers/cinder_controller.go @@ -164,6 +164,10 @@ func (r *CinderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res // Always patch the instance status when exiting this function so we can persist any changes. defer func() { condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions) + if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) { + instance.Status.Conditions.Set( + instance.Status.Conditions.Mirror(condition.ReadyCondition)) + } err := helper.PatchInstance(ctx, instance) if err != nil { _err = err @@ -172,9 +176,8 @@ func (r *CinderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res }() // Always initialize conditions used later as Status=Unknown - // except ReadyCondition which is False unless proven otherwise cl := condition.CreateList( - condition.FalseCondition(condition.ReadyCondition, condition.InitReason, condition.SeverityInfo, condition.ReadyInitMessage), + condition.UnknownCondition(condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage), condition.UnknownCondition(condition.DBReadyCondition, condition.InitReason, condition.DBReadyInitMessage), condition.UnknownCondition(condition.DBSyncReadyCondition, condition.InitReason, condition.DBSyncReadyInitMessage), condition.UnknownCondition(condition.RabbitMqTransportURLReadyCondition, condition.InitReason, condition.RabbitMqTransportURLReadyInitMessage), diff --git a/controllers/cinderapi_controller.go b/controllers/cinderapi_controller.go index c943748a..209ca796 100644 --- a/controllers/cinderapi_controller.go +++ b/controllers/cinderapi_controller.go @@ -148,6 +148,10 @@ func (r *CinderAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( // Always patch the instance status when exiting this function so we can persist any changes. defer func() { condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions) + if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) { + instance.Status.Conditions.Set( + instance.Status.Conditions.Mirror(condition.ReadyCondition)) + } err := helper.PatchInstance(ctx, instance) if err != nil { _err = err @@ -157,6 +161,7 @@ func (r *CinderAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( // Always initialize conditions used later as Status=Unknown cl := condition.CreateList( + condition.UnknownCondition(condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage), condition.UnknownCondition(condition.ExposeServiceReadyCondition, condition.InitReason, condition.ExposeServiceReadyInitMessage), condition.UnknownCondition(condition.InputReadyCondition, condition.InitReason, condition.InputReadyInitMessage), condition.UnknownCondition(condition.ServiceConfigReadyCondition, condition.InitReason, condition.ServiceConfigReadyInitMessage), diff --git a/controllers/cinderbackup_controller.go b/controllers/cinderbackup_controller.go index d2242841..d86186e6 100644 --- a/controllers/cinderbackup_controller.go +++ b/controllers/cinderbackup_controller.go @@ -132,6 +132,10 @@ func (r *CinderBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request // Always patch the instance status when exiting this function so we can persist any changes. defer func() { condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions) + if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) { + instance.Status.Conditions.Set( + instance.Status.Conditions.Mirror(condition.ReadyCondition)) + } err := helper.PatchInstance(ctx, instance) if err != nil { _err = err @@ -141,6 +145,7 @@ func (r *CinderBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request // Always initialize conditions used later as Status=Unknown cl := condition.CreateList( + condition.UnknownCondition(condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage), condition.UnknownCondition(condition.InputReadyCondition, condition.InitReason, condition.InputReadyInitMessage), condition.UnknownCondition(condition.ServiceConfigReadyCondition, condition.InitReason, condition.ServiceConfigReadyInitMessage), condition.UnknownCondition(condition.DeploymentReadyCondition, condition.InitReason, condition.DeploymentReadyInitMessage), diff --git a/controllers/cinderscheduler_controller.go b/controllers/cinderscheduler_controller.go index b7f72f5b..dbe92c91 100644 --- a/controllers/cinderscheduler_controller.go +++ b/controllers/cinderscheduler_controller.go @@ -132,6 +132,10 @@ func (r *CinderSchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Requ // Always patch the instance status when exiting this function so we can persist any changes. defer func() { condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions) + if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) { + instance.Status.Conditions.Set( + instance.Status.Conditions.Mirror(condition.ReadyCondition)) + } err := helper.PatchInstance(ctx, instance) if err != nil { _err = err @@ -141,6 +145,7 @@ func (r *CinderSchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Requ // Always initialize conditions used later as Status=Unknown cl := condition.CreateList( + condition.UnknownCondition(condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage), condition.UnknownCondition(condition.InputReadyCondition, condition.InitReason, condition.InputReadyInitMessage), condition.UnknownCondition(condition.ServiceConfigReadyCondition, condition.InitReason, condition.ServiceConfigReadyInitMessage), condition.UnknownCondition(condition.DeploymentReadyCondition, condition.InitReason, condition.DeploymentReadyInitMessage), diff --git a/controllers/cindervolume_controller.go b/controllers/cindervolume_controller.go index 981f027c..464d039f 100644 --- a/controllers/cindervolume_controller.go +++ b/controllers/cindervolume_controller.go @@ -134,6 +134,10 @@ func (r *CinderVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Request // Always patch the instance status when exiting this function so we can persist any changes. defer func() { condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions) + if instance.Status.Conditions.IsUnknown(condition.ReadyCondition) { + instance.Status.Conditions.Set( + instance.Status.Conditions.Mirror(condition.ReadyCondition)) + } err := helper.PatchInstance(ctx, instance) if err != nil { _err = err @@ -143,6 +147,7 @@ func (r *CinderVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Request // Always initialize conditions used later as Status=Unknown cl := condition.CreateList( + condition.UnknownCondition(condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage), condition.UnknownCondition(condition.InputReadyCondition, condition.InitReason, condition.InputReadyInitMessage), condition.UnknownCondition(condition.ServiceConfigReadyCondition, condition.InitReason, condition.ServiceConfigReadyInitMessage), condition.UnknownCondition(condition.DeploymentReadyCondition, condition.InitReason, condition.DeploymentReadyInitMessage),