How to run tests importing other files on k6-operator

Hi,
I’m using this tutorial to test on a distributed environment, but I’m having issues running tests files that import other test files.
Is it possible running a test that imports another test file, if so, how can I do that?
I’m using this command to upload the main file: kubectl create configmap scenarios-test --from-file scenarios.js but I do not know how to create the related file that I import inside scenarios.js

Hi @jesselemos

Welcome to the forum! You can create a configmap with several data entries like this:

kubectl create configmap scenarios-test --from-file test.js --from-file utils.js

If there are too many files to specify manually, kubectl allows specifying a folder there too:

kubectl create configmap scenarios-test --from-file=./test

Alternatively, you can create an archive with k6:

k6 archive test.js

Which will create an archive.tar in your current folder. Then you can put that archive into configmap:

kubectl create configmap scenarios-test --from-file=archive.tar

And specify it in your yaml for K6 deployment:

...
spec:
  parallelism: 1
  script:
    configMap:
      name: "crocodile-stress-test"
      file: "archive.tar" # <-- change here

It’s actually in my TODO list to add this info about tests with multiple files to k6-operator’s README right now and I hope to put it up there in coming days so your question is right on time :smile: Please share if something doesn’t work!

1 Like

Hi @olha,

thanks a lot for your quick and detailed answer.

The archive option worked really well for me.

Regards,
Jesse

1 Like

Hi,
What about to send environment vars? As I am having a great headache with this need and it seems to be k6 operator is limited with this features.

for example I run this CR :
apiVersion: k6.io/v1alpha1
kind: K6
metadata:
name: k6-sample
namespace: k6-operator
spec:
parallelism: 4
script:
configMap:
name: test
file: archive.tar
env:
- name: CLIENTID
value: 1234
- name: secret
value: sdadasdadadada

error: error validating “k6-testCR.yaml”: error validating data: ValidationError(K6.spec.script): unknown field “env” in io.k6.v1alpha1.K6.spec.script; if you choose to ignore these errors, turn validation off with --validate=false

Hi @cesarcorrea,

It looks like you have wrong syntax in the yaml. It should be something like:

...
spec:
  runner:
    env:
      - name: CLIENTID
        value: 1234
      - name: secret
        value: "sdadasdadadada"

PS Just in case, if you need to post another yaml snippet, please use a preformatted text (there is such an option in the edit form of this forum) so that formatting is precise. Thanks!

1 Like

nice! it is working now! thanks a lot buddy

apiVersion: k6.io/v1alpha1
kind: K6
metadata:
  name: k6-sample
  namespace: k6-operator-system
spec:
  parallelism: 2
  script:
    configMap:
      name: cashmaker-test
      file: archive.tar
  runner:
    env:
      - name: ID
        value: 123
      - name: SECRET
        value: "xxxxxxxxxxxx"