From 63fbadc8cbbe807efea3d532f8c9a1635edb3d49 Mon Sep 17 00:00:00 2001 From: Olha Yevtushenko Date: Fri, 9 Dec 2022 19:53:16 +0200 Subject: [PATCH] initializer: return error once on error from k6 --- pkg/resources/jobs/initializer.go | 4 +++- pkg/resources/jobs/initializer_test.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/resources/jobs/initializer.go b/pkg/resources/jobs/initializer.go index 78e8be75..cfd34f13 100644 --- a/pkg/resources/jobs/initializer.go +++ b/pkg/resources/jobs/initializer.go @@ -58,12 +58,13 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) { ) command, istioEnabled := newIstioCommand(k6.Spec.Scuttle.Enabled, []string{"sh", "-c"}) command = append(command, fmt.Sprintf( - "k6 archive %s -O %s %s 2> /tmp/k6logs && k6 inspect --execution-requirements %s 2> /tmp/k6logs ; cat /tmp/k6logs | grep 'level=error' || true", + "k6 archive %s -O %s %s 2> /tmp/k6logs && k6 inspect --execution-requirements %s 2> /tmp/k6logs ; ! cat /tmp/k6logs | grep 'level=error'", scriptName, archiveName, argLine, archiveName)) env := append(newIstioEnvVar(k6.Spec.Scuttle, istioEnabled), k6.Spec.Runner.Env...) + var zero32 int32 return &batchv1.Job{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-initializer", k6.Name), @@ -72,6 +73,7 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) { Annotations: annotations, }, Spec: batchv1.JobSpec{ + BackoffLimit: &zero32, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, diff --git a/pkg/resources/jobs/initializer_test.go b/pkg/resources/jobs/initializer_test.go index 36bfa35a..53248e33 100644 --- a/pkg/resources/jobs/initializer_test.go +++ b/pkg/resources/jobs/initializer_test.go @@ -19,6 +19,7 @@ func TestNewInitializerJob(t *testing.T) { } automountServiceAccountToken := true + zero := int32(0) expectedOutcome := &batchv1.Job{ ObjectMeta: metav1.ObjectMeta{ @@ -34,6 +35,7 @@ func TestNewInitializerJob(t *testing.T) { }, }, Spec: batchv1.JobSpec{ + BackoffLimit: &zero, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ @@ -58,7 +60,7 @@ func TestNewInitializerJob(t *testing.T) { Name: "k6", Command: []string{ "sh", "-c", - "k6 archive --log-output=none /test/test.js -O ./test.js.archived.tar --out cloud && k6 inspect --execution-requirements --log-output=none ./test.js.archived.tar", + "k6 archive /test/test.js -O ./test.js.archived.tar --out cloud 2> /tmp/k6logs && k6 inspect --execution-requirements ./test.js.archived.tar 2> /tmp/k6logs ; ! cat /tmp/k6logs | grep 'level=error'", }, Env: []corev1.EnvVar{}, Resources: corev1.ResourceRequirements{},