How to access/edit the exec.test.options.scenarios.default.stages[0]

Hi friends.
I am requiering to edit the STAGES in the OPTIONS as I am sending the target and duration values as an argument in the runner of my configmap, as follow:

kind: K6
  name: k6-sample
  namespace: k6-operator-system
  parallelism: 2
      name: buyer-simulation
      file: archive.tar
  arguments: --out statsd --env K6_STATSD_ADDR=newrelic-statsd.newrelic:80 --env K6_STATSD_ENABLE_TAGS=true
      - name: CLIENTID
        value: "client_id"
      - name: CLIENTSECRET
        value: "client_secret"
      - name: RPS
        value: "5"
      - name: DURATION
        value: "60s"

On another side, in my main.js I capture the values as follow:

const inputStages = {

    target : `${__ENV.RPS}`,
    duration : `'${__ENV.DURATION}'`

stage = JSON.parse(inputStages)
export const options = {
  setupTimeout: '120s',
  scenarios: {
    post_something: {
      executor: 'ramping-arrival-rate',
      startTime: '1s',
      startRate: 1,
      timeUnit: '1s',
      stages: stage,

such solution did not work, throwing the error when I launch the command “k6 archive main.js”, which is totally neccesary to wrap or zip all the files imported on my main.js :

syntaxError: invalid character 'o' looking for beginning of value
        at parse (native)

But I think that a good approach is being able to edit the options with “exec” library imported from k6/execution


But as many of you know, this is read only objetc.

¿what can I do?
PD: My purpose is to allow the developers be able to build their own target and duration, by a tool that I already have set named Rundeck, which is very useful to create basic forms and pass the values through a python script that overrides the parameters into my configmap , ready to be used by my k6 k8s operator :wink:
It’s fancy.

thank you all!

The problem here is that you are trying to JSON.parse() something that is not JSON. inputStages is already a JS object that you can directly use in the options, no need to parse it or transform it in any way.

Hi ned, thanks for answering!
Well, you are right. I can omit the JSON.parse. BTW the issue persist, as ‘k6 archive main.js’ breaks when it finds an empty assignation of env vars in
target : ${__ENV.RPS}, duration : ‘${__ENV.DURATION}’``

it’s very weird or I am not able to understand the reason hehe.
¿could you please explain to me why occurs that when k6 tries to archive the file?
Otherwise, if you have a good approach under the hat to allow the developer to define the target and duration by CLI (in my case by a configmap with k6 operator) as well as the archiving ends up completly, it would be great.


The k6 archive bundle is a combination of a test script, all of its imports and dependencies, and its options. You cannot have empty or invalid options in a script .tar archive.

And while you can overwrite whatever options were present in the archive directly (with k6 run --vus X --iterations Y archive.tar), you can’t overwrite the options with --env environment variables like how you are trying to do it, sorry.

@olha, do you have some ideas on how to decouple complicated script options (e.g. scenarios) with k6 archives in the context of k6-operator? Can users pass a config.json file and run the test essentially with k6 run --config /path/to/their/custom/config.json archive.tar? :thinking:

1 Like

Thanks Ned,

Let me say that I run my python script (orchestrated by Rundeck) that overrides whatever word/number in a file, and it worked fine replacing values in archive.tar So, I won’t be using the _ENV vars anymore.


The problem seems to be resolved in another way, but just for info then. Config can be used with the k6-operator via mounted volume (volumeClaim CRD option). AFAIS, that would be the workaround in this case. I suppose one could also store options struct in separate JS files and pick the necessary file during deployment stage, either via k6 archive-ing or via volume again. Either way, k6-operator is not touching scenarios option so it should be passed as is.

1 Like