From 9da97af9244a5d2fb844fc39374d7fa806e1fcea Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Thu, 21 Sep 2023 00:13:13 +0200 Subject: [PATCH] fix: treat Failed as error during test init Signed-off-by: Jorge Turrado --- controllers/common.go | 11 ++++++++++- controllers/k6_initialize.go | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/controllers/common.go b/controllers/common.go index c0c775bd..6e55fbf2 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" "time" @@ -46,7 +47,15 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.K6, c clie } // there should be only 1 initializer pod - if podList.Items[0].Status.Phase != "Succeeded" { + switch podList.Items[0].Status.Phase { + case "Succeeded": + // nothing to do + case "Failed": + // the init job has failed + returnErr = errors.New("init job has failed") + log.Error(returnErr, "error:") + return + default: log.Info("Waiting for initializing pod to finish") return } diff --git a/controllers/k6_initialize.go b/controllers/k6_initialize.go index 93d0ae18..eb98d101 100644 --- a/controllers/k6_initialize.go +++ b/controllers/k6_initialize.go @@ -52,7 +52,11 @@ func RunValidations(ctx context.Context, log logr.Logger, k6 *v1alpha1.K6, r *K6 inspectOutput, inspectReady, err := inspectTestRun(ctx, log, *k6, r.Client) if err != nil { - // inspectTestRun made a log message already so just return without requeue + // if there is any error, we have to reflect it on the K6 manifest + k6.Status.Stage = "error" + if _, err := r.UpdateStatus(ctx, k6, log); err != nil { + return ctrl.Result{}, err + } return ctrl.Result{}, nil } if !inspectReady {