Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: can be set environment variable from envFrom in k6 CR. #122

Closed
mugioka opened this issue Jun 30, 2022 · 5 comments · Fixed by #129
Closed

Feature request: can be set environment variable from envFrom in k6 CR. #122

mugioka opened this issue Jun 30, 2022 · 5 comments · Fixed by #129
Labels
enhancement New feature or request

Comments

@mugioka
Copy link
Contributor

mugioka commented Jun 30, 2022

motivation

When executing k6 scripts, we need to handle sensitive information such as API Key in environment variables, but currently we cannot define environment variables in envFrom, so we are having trouble handling sensitive information.
By enabling envFrom to be used with k6 CR, secret information can be managed with secret resources, making it possible to handle secret information more securely.

@BarthV
Copy link

BarthV commented Jun 30, 2022

https://github.com/grafana/k6-operator/blob/main/api/v1alpha1/k6_types.go#L53-L65

K6 specs Runner key is (almost) a standard kubernetes pod spec, it includes standard []corev1.EnvVar spec for env specifications.
So you can perfectly add standard pod env specs usign any existing configMap or Secret.

An example from my own test suites :

apiVersion: k6.io/v1alpha1
kind: K6
metadata:
  name: k6
spec:
  parallelism: 2
  script:
    localFile: /k6/pipeline.js
  arguments: --stage 120s:180 --stage 300s:360 --stage 420s:360 --stage 60s:0
  runner:
    env:
    - name: FOOBAR
      value: http://foo.bar
    - name: SECRET
      valueFrom:
        secretKeyRef:
          name: my-api-secret
          key: secret
    - name: SOME_VAR
      value: any-value

@mugioka
Copy link
Contributor Author

mugioka commented Jun 30, 2022

Ah, sure, but I think it would be better to be able to use envFrom if you want to handle multiple environment variables.

@yorugac
Copy link
Collaborator

yorugac commented Jul 15, 2022

I'm inclined to agree that env is sufficient in many cases, esp. since k6-operator is fully on-premise deployment anyway. So it seems like envFrom is more about convenience than anything else. But that's important too and I'll be happy to merge it as a PR. Thank you 😄

@yorugac yorugac added the enhancement New feature or request label Jul 15, 2022
yorugac pushed a commit that referenced this issue Jul 18, 2022
…ner/starter. (#129)

* feat: ability to set the environment variables with envFrom in k6 runner/starter.

Closes #122.

* imprv: add comment for envFrom definition.
@deepikaUKG
Copy link

How do we access the env variable in K6 file. Unable to access as __ENV.myVar

@yorugac
Copy link
Collaborator

yorugac commented Mar 17, 2023

@deepikaUKG This is a closed issue 🙂 Please consult official k6 docs and community forum regarding env vars in k6 scripts. If the problem persists, feel free to open a new forum topic or, if you're certain its a bug, open a bug report on Github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants