Skip to content

Conversation

@sahilsk
Copy link

@sahilsk sahilsk commented Aug 29, 2025

What

This PR adds support for environment variable interpolation in the arguments field of the TestRun CRD.


Why

When running a k6 test with multiple pods, all pods try to generate the same output files (e.g., report.json). This leads to file overwrites and a loss of individual pod metrics. This change allows users to use environment variables like ${POD_NAME} to create unique filenames for each pod's output, preventing data loss. For example, -o json=myoutput-${POD_NAME}.json would now correctly generate myoutput-k6-test-run-1.json, myoutput-k6-test-run-2.json, etc.

Refers: #162


How

The jobs/runner.go file was updated to:

  1. Collect all environment variables from the TestRun CRD.
  2. Use a custom function to iterate over the arguments string and replace any $VAR or ${VAR} placeholders with their corresponding values.
  3. Append the fully interpolated arguments to the final command, ensuring the k6 binary receives the correct, unique file paths.

@sahilsk sahilsk requested a review from yorugac as a code owner August 29, 2025 19:50
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sahilsk sahilsk marked this pull request as draft August 29, 2025 19:50
@sahilsk
Copy link
Author

sahilsk commented Aug 29, 2025

@ppcano @heitortsergent @yorugac can i have your early feedback on this Draft PR please

@yorugac
Copy link
Collaborator

yorugac commented Sep 28, 2025

Hi @sahilsk, thank you for looking into this problem! Before the code review, I have several questions here.

Firstly, have you evaluated other options for this problem? For example, other libraries or even adding a hand-written solution. In general, this flow of logic is likely the right one (get env vars for runner and pass arguments' string through some kind of substitution), but I'm not certain about relying on this library.

Also, is it possible to have a Kubernetes-style interpolation instead? I.e. with "$(VAR)". Speaking of, I'd look into what Kubernetes is using for that interpolation under-the-hood: perhaps, it can be re-used.

Lastly, of course, I wonder about edge cases here: are there any?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants