grafana / k6-operator

An operator for running distributed k6 tests.
Apache License 2.0
592 stars 166 forks source link

Handle error when copying log from initializer in controller #456

Closed pablochacin closed 1 month ago

pablochacin commented 2 months ago

Brief summary

When investigating an error running a test I fund this message in the controller's log:

2024-08-28T16:57:38Z    ERROR   controllers.TestRun     unable to marshal: ``   {"namespace": "default", "name": "mytest", "reconcileID": "0f346969-ff9a-4e00-bf96-22c3ff880675", "error": "unexpected end of JSON input"}
github.com/grafana/k6-operator/controllers.inspectTestRun
        /workspace/controllers/common.go:111

Looking at the code I found an unhandled error when reading logs from the pod (line 104) that can be hiding the root cause of this error:

102 buf := new(bytes.Buffer)
103 _, returnErr = io.Copy(buf, podLogs)
104 if err != nil {    <--- this should be returnErr
105     log.Error(err, "unable to copy logs from the pod")
106     return
107 }
108
109 if returnErr = json.Unmarshal(buf.Bytes(), &inspectOutput); returnErr != nil {
110     // this shouldn't normally happen but if it does, let's log output by default
111     log.Error(returnErr, fmt.Sprintf("unable to marshal: `%s`", buf.String()))
112 }

k6-operator version or image

v0.0.16

Helm chart version (if applicable)

No response

TestRun / PrivateLoadZone YAML

apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
  name: mytest
spec:
  parallelism: 1
  script:
    configMap:
      name: k6test
      file: sqlite.js
  runner:
    image: ghcr.io/grafana/k6exec:latest

Other environment details (if applicable)

Trying to run a test with a custom runner image

Steps to reproduce the problem

N/A

Expected behaviour

N/A

Actual behaviour

N/A

yorugac commented 2 months ago

Thanks for reporting this, @pablochacin! Yes, this looks like a typo 🙁