grafana / k6-operator

An operator for running distributed k6 tests.
Apache License 2.0
576 stars 158 forks source link

Support runners in specified namespace #205

Closed thestevenbell closed 1 year ago

thestevenbell commented 1 year ago

Requesting the ability to execute test runner pods in specified namespace.

apiVersion: k6.io/v1alpha1
kind: K6
metadata:
  name: k6
  namespace:    k6-operator-system
spec:
  parallelism: 1
  script:
    configMap:
      file: test.js
  arguments: --tag testid=k6-output-grafana-9 --out experimental-prometheus-rw
  runner:
    resources:
      limits:
        cpu: 200m
        memory: 1000Mi
      requests:
        cpu: 100m
        memory: 500Mi
    env:
      - name: K6_PROMETHEUS_RW_SERVER_URL
        value: http://sre-kube-prometheus-stack-prometheus.prometheus.svc.cluster.local:9090/api/v1/write
      - name: K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM
        value: "false"
      - name: K6_PROMETHEUS_RW_STALE_MARKERS
        value: "true"
      - name: K6_PROMETHEUS_RW_PUSH_INTERVAL
        value: 2s
    metadata:
      namespace: sre
error: error validating "k8s/k6s.yaml": error validating data: ValidationError(K6.spec.runner.metadata): unknown field "namespace" in io.k6.v1alpha1.K6.spec.runner.metadata; if you choose to ignore these errors, turn validation off with --validate=false
pears-one commented 1 year ago

You can just create the K6 resource in the SRE namespace and the pods will get started there.

thestevenbell commented 1 year ago

The request is the be able to create the K6 resource in any namespace and have the runner pods start in that namespace.

yorugac commented 1 year ago

Hi @thestevenbell, it seems to me like there's an error in this yaml: the namespace should be only in metadata, not in spec. So you should try smth like this:

apiVersion: k6.io/v1alpha1
kind: K6
metadata:
  name: k6
  namespace: sre # <--- namespace where pods will be created
spec:
  parallelism: 1
  script:
    configMap:
      file: test.js
  arguments: --tag testid=k6-output-grafana-9 --out experimental-prometheus-rw
  runner:
    resources:
      limits:
        cpu: 200m
        memory: 1000Mi
      requests:
        cpu: 100m
        memory: 500Mi
    env:
      - name: K6_PROMETHEUS_RW_SERVER_URL
        value: http://sre-kube-prometheus-stack-prometheus.prometheus.svc.cluster.local:9090/api/v1/write
      - name: K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM
        value: "false"
      - name: K6_PROMETHEUS_RW_STALE_MARKERS
        value: "true"
      - name: K6_PROMETHEUS_RW_PUSH_INTERVAL
        value: 2s
thestevenbell commented 1 year ago

Indeed. Creating the K6 resource in a namespace will result in runner pods executing the same namespace. Closing this request.