Skip to content

Commit

Permalink
feat: differentiate between Runner and Initializer initContainers (#379)
Browse files Browse the repository at this point in the history
* feat: differentiate between Runner and Initializer initContainers

* feat: added example for usage

* fix: readded pointer

* fix: fixed linting issue
  • Loading branch information
FloGro3 authored Mar 18, 2024
1 parent 87ca93b commit c2e81d8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
19 changes: 19 additions & 0 deletions config/samples/k6_v1alpha1_k6_with_initContainers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
apiVersion: k6.io/v1alpha1
kind: K6
metadata:
name: k6-sample
spec:
parallelism: 4
script:
configMap:
name: k6-test
file: test.js
initializer:
initContainers:
- image: busybox:latest
command: ["sh", "-c", "echo 'is part of initializer pod'"]
runner:
initContainers:
- image: busybox:latest
command: ["sh", "-c", "echo 'is part of all 4 testrun pods'"]
8 changes: 4 additions & 4 deletions pkg/resources/jobs/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ func newIstioEnvVar(istio v1alpha1.K6Scuttle, istioEnabled bool) []corev1.EnvVar
}

// TODO: Envoy variables are not passed to init containers
func getInitContainers(k6Spec *v1alpha1.TestRunSpec, script *types.Script) []corev1.Container {
func getInitContainers(pod *v1alpha1.Pod, script *types.Script) []corev1.Container {
var initContainers []corev1.Container

for i, k6InitContainer := range k6Spec.Runner.InitContainers {
for i, k6InitContainer := range pod.InitContainers {

name := fmt.Sprintf("k6-init-%d", i)
if k6InitContainer.Name != "" {
Expand All @@ -138,8 +138,8 @@ func getInitContainers(k6Spec *v1alpha1.TestRunSpec, script *types.Script) []cor
EnvFrom: k6InitContainer.EnvFrom,
Env: k6InitContainer.Env,
VolumeMounts: volumeMounts,
ImagePullPolicy: k6Spec.Runner.ImagePullPolicy,
SecurityContext: &k6Spec.Runner.ContainerSecurityContext,
ImagePullPolicy: pod.ImagePullPolicy,
SecurityContext: &pod.ContainerSecurityContext,
}
initContainers = append(initContainers, initContainer)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/jobs/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func NewInitializerJob(k6 v1alpha1.TestRunI, argLine string) (*batchv1.Job, erro
SecurityContext: &k6.GetSpec().Initializer.SecurityContext,
RestartPolicy: corev1.RestartPolicyNever,
ImagePullSecrets: k6.GetSpec().Initializer.ImagePullSecrets,
InitContainers: getInitContainers(k6.GetSpec(), script),
InitContainers: getInitContainers(k6.GetSpec().Initializer, script),
Containers: []corev1.Container{
{
Image: image,
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func NewRunnerJob(k6 v1alpha1.TestRunI, index int, token string) (*batchv1.Job,
TopologySpreadConstraints: k6.GetSpec().Runner.TopologySpreadConstraints,
SecurityContext: &k6.GetSpec().Runner.SecurityContext,
ImagePullSecrets: k6.GetSpec().Runner.ImagePullSecrets,
InitContainers: getInitContainers(k6.GetSpec(), script),
InitContainers: getInitContainers(&k6.GetSpec().Runner, script),
Containers: []corev1.Container{{
Image: image,
ImagePullPolicy: k6.GetSpec().Runner.ImagePullPolicy,
Expand Down

0 comments on commit c2e81d8

Please sign in to comment.