Skip to content

Commit

Permalink
Combine all initializer commands with && to catch any failing commands
Browse files Browse the repository at this point in the history
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
  • Loading branch information
frittentheke committed Aug 23, 2024
1 parent d9490de commit 33d10ee
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func inspectTestRun(ctx context.Context, log logr.Logger, k6 v1alpha1.TestRunI,
defer podLogs.Close()

buf := new(bytes.Buffer)
_, returnErr = io.Copy(buf, podLogs)
_, err = io.Copy(buf, podLogs)
if err != nil {
log.Error(err, "unable to copy logs from the pod")
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/jobs/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewInitializerJob(k6 v1alpha1.TestRunI, argLine string) (*batchv1.Job, erro
// printing JSON as usual. Then parse temp file only for errors, ignoring
// any other log messages.
// Related: https://github.com/grafana/k6-docs/issues/877
"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'",
"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'",
archiveName, scriptName, archiveName, argLine,
archiveName))

Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/jobs/initializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestNewInitializerJob(t *testing.T) {
Name: "k6",
Command: []string{
"sh", "-c",
"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'",
"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 -e 'level=error'",
},
Env: []corev1.EnvVar{},
EnvFrom: []corev1.EnvFromSource{
Expand Down

0 comments on commit 33d10ee

Please sign in to comment.