{"id":15062584,"url":"https://github.com/grafana/xk6-environment","last_synced_at":"2026-04-03T14:05:09.782Z","repository":{"id":257784018,"uuid":"677119794","full_name":"grafana/xk6-environment","owner":"grafana","description":"Let's extend k6 with some environments!","archived":false,"fork":false,"pushed_at":"2024-09-19T15:47:05.000Z","size":287,"stargazers_count":1,"open_issues_count":12,"forks_count":0,"subscribers_count":108,"default_branch":"main","last_synced_at":"2024-12-17T04:07:25.161Z","etag":null,"topics":["e2e","environment","k6","k6-operator","kubernetes","reliability","vcluster"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grafana.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-10T19:36:30.000Z","updated_at":"2024-09-19T15:47:01.000Z","dependencies_parsed_at":"2024-09-20T06:54:39.476Z","dependency_job_id":null,"html_url":"https://github.com/grafana/xk6-environment","commit_stats":null,"previous_names":["grafana/xk6-environment"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafana%2Fxk6-environment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafana%2Fxk6-environment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafana%2Fxk6-environment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grafana%2Fxk6-environment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grafana","download_url":"https://codeload.github.com/grafana/xk6-environment/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237951347,"owners_count":19392680,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["e2e","environment","k6","k6-operator","kubernetes","reliability","vcluster"],"created_at":"2024-09-24T23:43:17.001Z","updated_at":"2026-04-03T14:05:09.769Z","avatar_url":"https://github.com/grafana.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"**xk6-environment** provides a way to simplify definition of a k6 test with environment attached. This allows to bootstrap and execute the test within specific environment in a repeatable fashion while keeping the environment isolated.\n\n\u003e [!WARNING] \n\u003e xk6-environment is an experimental extension. Consider limitations below and existing GitHub issues before usage.\n\nSome use cases for xk6-environment:\n- As a first-class object, the environment itself can be viewed as a SUT (system under test).\n  - Answer questions like: does my environment reach a state X under conditions Y?\n- Repeatable execution of testing logic within a given environment, without resorting to additional Bash scripts around k6 invocation.\n- Infrastructure tests or experiments.\n- A way to share a k6 test with environment attached. E.g. a k6 test that illustrates an issue that happens only with a certain version of Prometheus deployment.\n\nCurrent implementation is done via [vcluster](https://www.vcluster.com/) tool which creates a virtual, \"ephemeral\" cluster within existing Kubernetes cluster.\n\n## Prerequisites\n\nYou need:\n- Access to Kubernetes cluster via `kubectl`.\n- Install [vcluster CLI](https://www.vcluster.com/docs/getting-started/setup).\n    - this requirement might be lifted in the future, see the [issue](https://github.com/grafana/xk6-environment/issues/1).\n\nThe simplest way to get started with xk6-environment:\n\n```bash\nmake build\n./k6 run example/sample.js\n```\n\n## How it works\n\nxk6-environment creates an environment by starting a new, virtual cluster within the Kubernetes cluster you're currently connected to.\n\nOptionally, a user can configure a folder with Kubernetes manifests which describes initial deployments within the environment. The extension doesn't check for correctness or validation anywhere: it will try to deploy and will report an error if it's not possible. In case of complex deployments, one can add a `kustomization.yaml` file to the folder: it will be located by xk6-environment and processed correctly. The easiest way to add a `kustomization.yaml` is to run the following command from your folder with manifests:\n\n```bash\nkustomize create --autodetect --recursive .\n```\n\nAt the end of the test the environment can be deleted which triggers removal of virtual cluster as well.\n\nThe basic workflow looks as follows:\n\n```js\nimport { Environment } from 'k6/x/environment';\nimport { sleep } from 'k6';\n\nexport const options = {\n  setupTimeout: '60s',\n};\n\nconst PARENT = \"...\"\n\nconst env = new Environment({\n  name: \"my-test-environment\",\n  implementation: \"vcluster\",\n  initFolder: PARENT, // initial folder with everything that wil be loaded at init\n})\n\nexport function setup() {\n  console.log(\"init returns\", env.init());\n\n}\n\nexport default function () {\n  // something meaningful happens here\n}\n\nexport function teardown() {\n  console.log(\"delete returns\", env.delete());\n}\n```\n\nThe rest of the provided methods allow to perform basic Kubernetes functions _within_ the environment. See `index.d.ts` for full description of available API.\n\n\u003c!-- More samples can be found here --\u003e\n\n## Limitations\n\nThe most important current limitations:\n- xk6-environment support only `VU: 1` tests. Given the nature of virtual environments, it is yet unclear if there is a use case that requires more than 1 VU.\n- Kubernetes context corresponding to vcluster is created on `create` method but not yet removed on `delete`.\n- Since xk6-environment accesses and edits your `KUBECONFIG`, if you tinker with it simultaneously with the test execution, the result might be unpredictable. For example, changing Kubernetes context during execution of xk6-environment test will likely make the test fail.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrafana%2Fxk6-environment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrafana%2Fxk6-environment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrafana%2Fxk6-environment/lists"}