Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of logic for error on duplicate job #367

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api/v1alpha1/k6conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func Initialize(k6 TestRunI) {

// PLZ test run case
if len(k6.GetSpec().TestRunID) > 0 {
UpdateCondition(k6, CloudTestRun, metav1.ConditionTrue)
UpdateCondition(k6, CloudPLZTestRun, metav1.ConditionTrue)
UpdateCondition(k6, CloudTestRunCreated, metav1.ConditionTrue)
UpdateCondition(k6, CloudTestRunFinalized, metav1.ConditionFalse)
Expand Down
6 changes: 4 additions & 2 deletions controllers/k6_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ func createJobSpecs(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
log.Info(err.Error())

// is it possible to implement this delay with resourceVersion of the job?

t, condUpdated := v1alpha1.LastUpdate(k6, v1alpha1.CloudTestRun)
// if condition has not been updated yet or has been updated very recently
if !condUpdated || time.Since(t).Seconds() <= 30 {
// If condition is unknown then resource hasn't been updated with `k6 inspect` results.
// If it has been updated but very recently, wait a bit before throwing an error.
if v1alpha1.IsUnknown(k6, v1alpha1.CloudTestRun) || !condUpdated || time.Since(t).Seconds() <= 30 {
// try again before returning an error
return ctrl.Result{RequeueAfter: time.Second * 10}, true, nil
}
Expand Down
10 changes: 7 additions & 3 deletions controllers/testrun_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ func (r *TestRunReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
return r.reconcile(ctx, req, log, k6)
}

func isCloudTestRun(k6 v1alpha1.TestRunI) bool {
return v1alpha1.IsTrue(k6, v1alpha1.CloudTestRun) || v1alpha1.IsTrue(k6, v1alpha1.CloudPLZTestRun)
}

func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log logr.Logger, k6 v1alpha1.TestRunI) (ctrl.Result, error) {
var err error
if v1alpha1.IsTrue(k6, v1alpha1.CloudTestRun) {
if isCloudTestRun(k6) {
// bootstrap the client
found, err := r.createClient(ctx, k6, log)
if err != nil {
Expand All @@ -100,7 +104,7 @@ func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log
// Decision making here is now a mix between stages and conditions.
// TODO: refactor further.

if v1alpha1.IsTrue(k6, v1alpha1.CloudTestRun) && v1alpha1.IsFalse(k6, v1alpha1.CloudTestRunAborted) {
if isCloudTestRun(k6) && v1alpha1.IsFalse(k6, v1alpha1.CloudTestRunAborted) {
// check in with the BE for status
if r.ShouldAbort(ctx, k6, log) {
log.Info("Received an abort signal from the k6 Cloud: stopping the test.")
Expand Down Expand Up @@ -141,7 +145,7 @@ func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log
msg := fmt.Sprintf(errMessageTooLong, "initializer pod", "initializer job and pod")
log.Info(msg)

if v1alpha1.IsTrue(k6, v1alpha1.CloudTestRun) {
if isCloudTestRun(k6) {
events := cloud.ErrorEvent(cloud.K6OperatorStartError).
WithDetail(msg).
WithAbort()
Expand Down
Loading