Skip to content

Commit 0561eb1

Browse files
committed
fix: logic for error on duplicate job
1 parent b1a5e24 commit 0561eb1

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

api/v1alpha1/k6conditions.go

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func Initialize(k6 TestRunI) {
8888

8989
// PLZ test run case
9090
if len(k6.GetSpec().TestRunID) > 0 {
91-
UpdateCondition(k6, CloudTestRun, metav1.ConditionTrue)
9291
UpdateCondition(k6, CloudPLZTestRun, metav1.ConditionTrue)
9392
UpdateCondition(k6, CloudTestRunCreated, metav1.ConditionTrue)
9493
UpdateCondition(k6, CloudTestRunFinalized, metav1.ConditionFalse)

controllers/k6_create.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ func createJobSpecs(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
8888
log.Info(err.Error())
8989

9090
// is it possible to implement this delay with resourceVersion of the job?
91+
9192
t, condUpdated := v1alpha1.LastUpdate(k6, v1alpha1.CloudTestRun)
92-
// if condition has not been updated yet or has been updated very recently
93-
if !condUpdated || time.Since(t).Seconds() <= 30 {
93+
// If condition is unknown then resource hasn't been updated with `k6 inspect` results.
94+
// If it has been updated but very recently, wait a bit before throwing an error.
95+
if v1alpha1.IsUnknown(k6, v1alpha1.CloudTestRun) || !condUpdated || time.Since(t).Seconds() <= 30 {
9496
// try again before returning an error
9597
return ctrl.Result{RequeueAfter: time.Second * 10}, true, nil
9698
}

controllers/testrun_controller.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ func (r *TestRunReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
8080
return r.reconcile(ctx, req, log, k6)
8181
}
8282

83+
func isCloudTestRun(k6 v1alpha1.TestRunI) bool {
84+
return v1alpha1.IsTrue(k6, v1alpha1.CloudTestRun) || v1alpha1.IsTrue(k6, v1alpha1.CloudPLZTestRun)
85+
}
86+
8387
func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log logr.Logger, k6 v1alpha1.TestRunI) (ctrl.Result, error) {
8488
var err error
85-
if v1alpha1.IsTrue(k6, v1alpha1.CloudTestRun) {
89+
if isCloudTestRun(k6) {
8690
// bootstrap the client
8791
found, err := r.createClient(ctx, k6, log)
8892
if err != nil {
@@ -100,7 +104,7 @@ func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log
100104
// Decision making here is now a mix between stages and conditions.
101105
// TODO: refactor further.
102106

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

144-
if v1alpha1.IsTrue(k6, v1alpha1.CloudTestRun) {
148+
if isCloudTestRun(k6) {
145149
events := cloud.ErrorEvent(cloud.K6OperatorStartError).
146150
WithDetail(msg).
147151
WithAbort()

0 commit comments

Comments
 (0)