grafana / k6-operator

An operator for running distributed k6 tests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for separate initContainers in initializer spec

nveces opened this issue · comments

Brief summary

I have a K6 yaml with the "initializer > initContainers" and "runner > initContainers":

initializer:
    initContainers:
      - name: test-init-01-clone
        image: busybox:1.28
        command: ['sh', '-c', 'echo "InitiContainer Waiting for task...."; sleep 10; echo "Task is done!!!"']
.../...
  runner:
    initContainers:
      - name: test-runner-01
        image: busybox:1.28
         command: ['sh', '-c', 'echo "Waiting for task...."; sleep 10; echo "Task is done!!!"']    

But, the "k6-loadtest-01-initializer-" pod shows the "test-runner-01" init-container.

I'm confused, I thought that the initializer pod would use the initializer and the runner pods the "runner > initContainer".

I want to clone a git repo at the begins of the initializer pod, this repo contains the Load Tests scripts and libraries and leaves the files on the volumepersistentclaim (PVC).

k6-operator version or image

ghcr.io/grafana/k6-operator:controller-v0.0.11rc1

K6 YAML

apiVersion: k6.io/v1alpha1
kind: K6
metadata:
  name: k6-loadtest-01
  namespace: k6-operator-system
  labels:
    app: k6-sso-loadtest-01
spec:

  initializer:
    initContainers:
      - name: test-init-01-clone
        image: busybox:1.28
        command: ['sh', '-c', 'echo "InitiContainer Waiting for task...."; sleep 10; echo "Task is done!!!"']
        volumes:
          - name: clone-repo
            gitRepo:
              directory: /test/project
              repositoy: https://anexamplepapthofgitlab.org/k6-loadtest.git
              revision: main
        volumeMounts:
          - name: clone-repo
            mountPath: /test
            readOnly: false
  
  parallelism: 1
  script:
    volumeClaim:
      name: k6-projects-pvc
      file:  project/loadtest/10-test.js
  runner:
    initContainers:
      - name: test-runner-01
        image: busybox:1.28
        command: ['sh', '-c', 'echo "Waiting for task...."; sleep 10; echo "Task is done!!!"']

Other environment details (if applicable)

No response

Steps to reproduce the problem

1/ Login in OpenShift/KUbernetes cluster
2/ Execute: oc apply -f k6-test-load.yaml
3/ go to the k6-operator-system namespace
4/ The k6-loadtest-01-intializer- pod has the init containers: "test-runner-01", defined in the "runner > initContainers" section.

Expected behaviour

The k6-loadtest-01-initializer should have the init container "test-init-01-clone", defined in the "initializer > initContainers" section.

Actual behaviour

The k6-loadtest-01-intializer- pod has the init containers: "test-runner-01", defined in the "runner > initContainers" section.

Hi @nveces, thanks for opening the issue! Yes, this is expected right now: init containers are not supposed to be defined additionally for initializer. I.e. initializer uses the init containers from runner and that's it. You can pass them to initializer spec only because that's how Pod is defined in Kubernetes (k6-operator cannot easily forbid such usage).

IIRC, there were discussions whether one would ever even need a separate init container in initializer pod; I see now that was a misconception 😂
This should be a pretty small change, in case someone would like to work on it.