Running shell commands before k6 test at k8 pods

I would like to run few shell commands before running a k6 test at k8 pods using k6-operator. Do we have any way to do this.

  automountServiceAccountToken: true
  - command:
    - sh
    - -c
    - k6 archive /test/TestScript.js -O ./TestScript.js.archived.tar 2>
      /tmp/k6logs && k6 inspect --execution-requirements ./TestScript.js.archived.tar
      2> /tmp/k6logs ; ! cat /tmp/k6logs | grep 'level=error'

Wanted to run before k6 archive command. It is required to run to do the load test for application.

Hi @ppyneni

Thanks for reaching out. I’m not 100% sure I understand the requirement. You can pass a k6 archive using a ConfigMap. Are you creating a custom k6 image for the runner which has the tests in several files (mounted or in the docker image), and you need to archive them to execute, as they are not? Can you not create the archived test before the run?

Apologies if I did not understand correctly. If you can clarify, I’ll reach to the operator developers for advice.



Maybe I understood incorrectly and you are not looking to run the k6 archive command. Can you share what command you need to add to the default k6 archive?

Depending on your requirements, would init containers work for you?

Thanks for the additional context.



Thank you @eyeveebe. Sorry for the late reply. I am using custom runner image. when the Pod is launched I want to runt the below command before k6 test starts in the k8 pods.

start telegraf

It would help us to get the summarized results. thanks!

Hi @ppyneni,

Thanks for clarification. This is a bit of an unusual use case since metric agents like telegraf are usually running all the time in the background, not started specifically for the test… E.g. isn’t the SUT itself generating metrics and thus requiring telegraf?

Either way, I believe it’ll be possible to start the telegraf agent with an init container once the PR linked above is finished and merged.

1 Like