From 1cd53f76fa200b79d8beb527f41644fca4361249 Mon Sep 17 00:00:00 2001 From: "michal.gubricky" Date: Thu, 4 Jan 2024 12:25:10 +0100 Subject: [PATCH] Add timeout logic Signed-off-by: michal.gubricky --- .../openstacknodeimagerelease_controller.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/controller/openstacknodeimagerelease_controller.go b/internal/controller/openstacknodeimagerelease_controller.go index 988eb00a..6e533686 100644 --- a/internal/controller/openstacknodeimagerelease_controller.go +++ b/internal/controller/openstacknodeimagerelease_controller.go @@ -188,8 +188,6 @@ func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req return ctrl.Result{}, fmt.Errorf("failed to get an image: %w", err) } - // TODO: Add timeout logic - import start time could be taken from OpenStackImageNotImportedYetReason condition, or somehow better - // Manage image statuses according to the guidelines outlined in https://docs.openstack.org/glance/stein/user/statuses.html. switch image.Status { case images.ImageStatusActive: @@ -234,6 +232,22 @@ func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req return ctrl.Result{}, err } + // Calculate elapsed time since last transition + startTime := conditions.GetLastTransitionTime(openstacknodeimagerelease, apiv1alpha1.OpenStackImageReadyCondition) + elapsedTime := time.Since(startTime.Time) + + // Check if the image has been active after 10 minutes + if image.Status != images.ImageStatusActive && elapsedTime > 10*time.Minute { + err = fmt.Errorf("Timeout waiting for image: %s to become active", image.Name) + conditions.MarkFalse(openstacknodeimagerelease, + apiv1alpha1.OpenStackImageReadyCondition, + apiv1alpha1.IssueWithOpenStackImageReason, + clusterv1beta1.ConditionSeverityError, + err.Error(), + ) + return ctrl.Result{}, err + } + // Requeue to ensure the image's presence return ctrl.Result{Requeue: true, RequeueAfter: reconcileImage}, nil }