Skip to content

Commit

Permalink
plz: fix double finalization
Browse files Browse the repository at this point in the history
  • Loading branch information
yorugac committed Jul 11, 2023
1 parent 348c0ba commit 77b8250
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion controllers/k6_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,19 @@ func (r *K6Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
// If this is a cloud test run in any mode, try to finalize it.
if k6.IsTrue(v1alpha1.CloudTestRun) &&
k6.IsFalse(v1alpha1.CloudTestRunFinalized) {

// If TestRunRunning has just been updated, wait for a bit before
// acting, to avoid race condition between different reconcile loops.
t, _ := k6.LastUpdate(v1alpha1.TestRunRunning)
if time.Now().Sub(t) < 5*time.Second {
return ctrl.Result{RequeueAfter: time.Second * 2}, nil
}

if err = cloud.FinishTestRun(r.K6CloudClient, k6.Status.TestRunID); err != nil {
log.Error(err, "Failed to finalize the test run with cloud output")
return ctrl.Result{}, nil
} else {
log.Info(fmt.Sprintf("Cloud test run %s was finalized succesfully", k6.Status.TestRunID))
log.Info(fmt.Sprintf("Cloud test run %s was finalized successfully", k6.Status.TestRunID))

k6.UpdateCondition(v1alpha1.CloudTestRunFinalized, metav1.ConditionTrue)
}
Expand Down

0 comments on commit 77b8250

Please sign in to comment.