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 Aug 4, 2023
1 parent 9093a0a commit 6ab0a1a
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 @@ -231,11 +231,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 6ab0a1a

Please sign in to comment.