Expose `options.cloud` in TestRun CRD spec and have it take precedence
illrill opened this issue · comments
As an extension of #309, I'd like to have the options.cloud
options exposed as fields in the TestRun spec. Or at least the options.cloud.projectID
option.
For example:
apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
name: k6-sample
spec:
parallelism: 4
options:
cloud:
projectID: 12345
Consider a multi-tenant Kubernetes environment, where the K6 Operator and K6 Cloud organization is managed centrally by a platform team, but TestRuns are created and managed by multiple different development teams (who have their own namespaces in the cluster, and their own pre-assigned Projects in K6 Cloud).
The way it is now, development teams are able to stream results to any random project (including the default project) by setting these options directly in the test script. If we externalize Project ID to the TestRun
spec, the platform team can e.g. use Kyverno or OPA Gatekeeper policies to enforce that development teams only stream test results to their own pre-assigned projects, and not anyone else's project or the default project.
The TestRun
spec.options.cloud.projectID
would have to take precedence/override the project ID set (or not set at all) in the test script itself.
Hi @illrill, thanks for the issue. The problem totally makes sense of course. But actually, project ID can be set with k6 itself:
https://k6.io/docs/cloud/creating-and-running-a-test/cloud-tests-from-the-cli/#change-test-project
It's a K6_CLOUD_PROJECT_ID
environment variable - it should be passed to the runner spec in TestRun
. Would that work for your case?
Thanks for pointing me in the right direction @yorugac. Environment variables are easily accessible by Kyverno, and they do take precedence over script options 👍