Hi,
I have installed the k6 operator on our GKE cluster using the helm chart.
I am facing an issue where I am unable to use variables from ConfigMap inside the TestRun.
While I can console.log
the env vars inside my function, I cannot access them inside export const options
hence the test fails at initializer stage itself.
Here is the error:
level=error msg="could not initialize '/test/api.js': could not load JS test 'file:///test/api.js': strconv.ParseInt: parsing \"undefined\": invalid syntax"
Here is my script which is saved as the ConfigMap for TestRun:
apiVersion: v1
data:
api.js: |
import http from 'k6/http';
import { check, fail } from 'k6';
import { sleep } from 'k6';
const url = 'https://url-to-test';
let rt = `${__ENV.RATE}`;
export const options = {
scenarios: {
constant_request_rate: {
executor: 'constant-arrival-rate',
rate: rt, // setting rate: `${__ENV.RATE}` does not work either
timeUnit: '1s', // 1000 iterations per second, i.e. 1000 RPS
duration: '5s',
preAllocatedVUs: 5, // how large the initial pool of VUs would be
maxVUs: 10, // if the preAllocatedVUs are not enough, we can initialize more
},
}
};
export default function() {
let res = http.get(url);
console.log(res.json(), rt);
}
kind: ConfigMap
metadata:
name: api-cm-test
namespace: podinfo
My ConfigMap with the Rate data:
apiVersion: v1
kind: ConfigMap
metadata:
name: api-data-cm
namespace: podinfo
data:
RATE: '1'
DURATION: 5s
And here is my TestRun config:
apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
name: api-test
namespace: podinfo
spec:
parallelism: 4
script:
configMap:
name: api-cm-test
file: api-eve.js
runner:
# env:
# - name: "RATE"
# value: '1'
envFrom:
- secretRef:
name: api-secret
- configMapRef:
name: api-data-cm
Even tried the Kubernetes way as you can see from env:
but this stlll does not work.