Skip to content

Commit a054bf7

Browse files
committed
Combine all initializer commands with && to catch any failing commands
By running two commands instead of one (the second being the cat | grep), any failures (non-zero exit code) of the first part (containing `k6 inspect`) will be lost and masked away. By chaining them all with `&&` the first non-zero RC will fail the whole command and return. Fixes: #435
1 parent d9490de commit a054bf7

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

controllers/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
100100
defer podLogs.Close()
101101

102102
buf := new(bytes.Buffer)
103-
_, returnErr = io.Copy(buf, podLogs)
103+
_, err = io.Copy(buf, podLogs)
104104
if err != nil {
105105
log.Error(err, "unable to copy logs from the pod")
106106
return

pkg/resources/jobs/initializer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func NewInitializerJob(k6 v1alpha1.TestRunI, argLine string) (*batchv1.Job, erro
7676
// printing JSON as usual. Then parse temp file only for errors, ignoring
7777
// any other log messages.
7878
// Related: https://github.com/grafana/k6-docs/issues/877
79-
"mkdir -p $(dirname %s) && k6 archive %s -O %s %s 2> /tmp/k6logs && k6 inspect --execution-requirements %s 2> /tmp/k6logs ; ! cat /tmp/k6logs | grep 'level=error'",
79+
"mkdir -p $(dirname %s) && k6 archive %s -O %s %s 2> /tmp/k6logs && k6 inspect --execution-requirements %s 2> /tmp/k6logs && ! cat /tmp/k6logs | grep 'level=error'",
8080
archiveName, scriptName, archiveName, argLine,
8181
archiveName))
8282

pkg/resources/jobs/initializer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestNewInitializerJob(t *testing.T) {
6363
Name: "k6",
6464
Command: []string{
6565
"sh", "-c",
66-
"mkdir -p $(dirname /tmp/test.js.archived.tar) && k6 archive /test/test.js -O /tmp/test.js.archived.tar --out cloud 2> /tmp/k6logs && k6 inspect --execution-requirements /tmp/test.js.archived.tar 2> /tmp/k6logs ; ! cat /tmp/k6logs | grep 'level=error'",
66+
"mkdir -p $(dirname /tmp/test.js.archived.tar) && k6 archive /test/test.js -O /tmp/test.js.archived.tar --out cloud 2> /tmp/k6logs && k6 inspect --execution-requirements /tmp/test.js.archived.tar 2> /tmp/k6logs && ! cat /tmp/k6logs | grep 'level=error'",
6767
},
6868
Env: []corev1.EnvVar{},
6969
EnvFrom: []corev1.EnvFromSource{

0 commit comments

Comments
 (0)