Skip to content

Commit

Permalink
Add timeout logic
Browse files Browse the repository at this point in the history
Signed-off-by: michal.gubricky <michal.gubricky@dnation.cloud>
  • Loading branch information
michal-gubricky committed Jan 4, 2024
1 parent 9b98e99 commit 1cd53f7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/controller/openstacknodeimagerelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 1cd53f7

Please sign in to comment.