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

Add helper function for creating random namespaces #73

Open
pablochacin opened this issue Oct 11, 2022 · 0 comments
Open

Add helper function for creating random namespaces #73

pablochacin opened this issue Oct 11, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@pablochacin
Copy link
Contributor

The main use case for the xk6-kubernetes extension is facilitating the setup of tests, by providing a simple API for creating Kubernetes resources such as secrets, pods, services and others required for running a test application.

When running multiple concurrent tests, it is convenient to isolate tests by using different namespaces when creating the resources needed by the tests. Moreover, it is convenient to use randomly generated namespaces for each test, to prevent interferences with other instances of the same tests running concurrently or that run previously and was not properly teared down.

This means that of such test scripts must include a sequence of code similar to the example below:

import { Kubernetes } from 'k6/x/kubernetes'
import { randomString } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';

const namespace = randomString(8)
       
const nsObj = {
    apiVersion: "v1",
    kind: "Namespace",
    metadata: {
        name: "test-ns"
    }
}


export  function setup() {
  const k8s = new Kubernetes()
  k8s.create(nsObj)
}

Being this a very common use case, In order to prevent this redundancy of code on each test, it will be convenient to provide a helper function that creates a new namespace with a random name and return its name, reducing the above sequence to this show below:

import { Kubernetes } from 'k6/x/kubernetes'


export function setup() {
  const k8s = new Kubernetes()
  namespace = k8s.randomNamespace()
}
@pablochacin pablochacin added the enhancement New feature or request label Oct 24, 2022
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

No branches or pull requests

1 participant