Skip to content

Commit

Permalink
Treat failed initializer as error (PR 291 continued) (#401)
Browse files Browse the repository at this point in the history
* Fixed so that if the initialization pod status becomes Error, TestRun also becomes Error.

* Improved error messages

Co-authored-by: Olha Yevtushenko <[email protected]>

---------

Co-authored-by: Olha Yevtushenko <[email protected]>
  • Loading branch information
irumaru and yorugac authored May 23, 2024
1 parent 6503bbb commit 6b38db7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"time"
Expand Down Expand Up @@ -54,7 +55,12 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
}

// there should be only 1 initializer pod
if podList.Items[0].Status.Phase != corev1.PodSucceeded && podList.Items[0].Status.Phase != corev1.PodFailed {
if podList.Items[0].Status.Phase == corev1.PodFailed {
returnErr = errors.New("initalizer job has failed")
log.Error(returnErr, "error:")
return
}
if podList.Items[0].Status.Phase != corev1.PodSucceeded {
log.Info("Waiting for initializing pod to finish")
return
}
Expand Down
8 changes: 8 additions & 0 deletions controllers/k6_initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func RunValidations(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
WithDetail(fmt.Sprintf("Failed to inspect the test script: %v", err)).
WithAbort()
cloud.SendTestRunEvents(r.k6CloudClient, v1alpha1.TestRunID(k6), log, events)
} else {
// if there is any error, we have to reflect it on the K6 manifest
k6.GetStatus().Stage = "error"
if _, err := r.UpdateStatus(ctx, k6, log); err != nil {
return ctrl.Result{}, ready, err
}

return ctrl.Result{}, ready, nil
}

// inspectTestRun made a log message already so just return without requeue
Expand Down

0 comments on commit 6b38db7

Please sign in to comment.