Skip to content

Commit 4dae317

Browse files
feat: support skipping initializer in testrun spec
1 parent 27fa754 commit 4dae317

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

api/v1alpha1/testrun_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ type PodMetadata struct {
3232
}
3333

3434
type Pod struct {
35+
// +optional
36+
// +kubebuilder:default=false
37+
Disabled bool `json:"disabled"`
3538
Affinity *corev1.Affinity `json:"affinity,omitempty"`
3639
AutomountServiceAccountToken string `json:"automountServiceAccountToken,omitempty"`
3740
Env []corev1.EnvVar `json:"env,omitempty"`
@@ -293,3 +296,10 @@ func (k6 *TestRun) ListOptions() *client.ListOptions {
293296

294297
return &client.ListOptions{LabelSelector: selector, Namespace: k6.NamespacedName().Namespace}
295298
}
299+
300+
func (k6 *TestRun) IsInitializerDisabled() bool {
301+
if k6.GetSpec().Initializer == nil {
302+
return false
303+
}
304+
return k6.GetSpec().Initializer.Disabled == true
305+
}

config/crd/bases/k6.io_testruns.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ spec:
558558
type: string
559559
type: object
560560
type: object
561+
disable:
562+
default: false
563+
type: boolean
561564
env:
562565
items:
563566
properties:
@@ -2593,6 +2596,9 @@ spec:
25932596
type: string
25942597
type: object
25952598
type: object
2599+
disable:
2600+
default: false
2601+
type: boolean
25962602
env:
25972603
items:
25982604
properties:
@@ -4649,6 +4655,9 @@ spec:
46494655
type: string
46504656
type: object
46514657
type: object
4658+
disable:
4659+
default: false
4660+
type: boolean
46524661
env:
46534662
items:
46544663
properties:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
apiVersion: k6.io/v1alpha1
3+
kind: TestRun
4+
metadata:
5+
name: k6-sample
6+
spec:
7+
parallelism: 4
8+
initializer:
9+
disabled: true
10+
script:
11+
configMap:
12+
name: k6-test
13+
file: test.js

docs/crd-generated.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo
869869
are set, the values in SecurityContext take precedence.<br/>
870870
</td>
871871
<td>false</td>
872+
</tr><tr>
873+
<td><b>disabled</b></td>
874+
<td>boolean</td>
875+
<td>
876+
<br/>
877+
<br/>
878+
<i>Default</i>: false<br/>
879+
</td>
880+
<td>false</td>
872881
</tr><tr>
873882
<td><b><a href="#testrunspecinitializerenvindex">env</a></b></td>
874883
<td>[]object</td>
@@ -9822,6 +9831,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo
98229831
are set, the values in SecurityContext take precedence.<br/>
98239832
</td>
98249833
<td>false</td>
9834+
</tr><tr>
9835+
<td><b>disabled</b></td>
9836+
<td>boolean</td>
9837+
<td>
9838+
<br/>
9839+
<br/>
9840+
<i>Default</i>: false<br/>
9841+
</td>
9842+
<td>false</td>
98259843
</tr><tr>
98269844
<td><b><a href="#testrunspecrunnerenvindex">env</a></b></td>
98279845
<td>[]object</td>
@@ -18797,6 +18815,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo
1879718815
are set, the values in SecurityContext take precedence.<br/>
1879818816
</td>
1879918817
<td>false</td>
18818+
</tr><tr>
18819+
<td><b>disabled</b></td>
18820+
<td>boolean</td>
18821+
<td>
18822+
<br/>
18823+
<br/>
18824+
<i>Default</i>: false<br/>
18825+
</td>
18826+
<td>false</td>
1880018827
</tr><tr>
1880118828
<td><b><a href="#testrunspecstarterenvindex">env</a></b></td>
1880218829
<td>[]object</td>

internal/controller/testrun_controller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log
140140
return ctrl.Result{}, err
141141
}
142142

143+
// Not a clout test and initializer is set to disabled
144+
// -> skip creating initializer job
145+
if !isCloudTestRun(k6) && k6.IsInitializerDisabled() {
146+
log.Info("Initializer is disabled, skipping initialization step")
147+
v1alpha1.UpdateCondition(k6, v1alpha1.InitializerSkipped, metav1.ConditionTrue)
148+
v1alpha1.UpdateCondition(k6, v1alpha1.CloudTestRun, metav1.ConditionFalse)
149+
v1alpha1.UpdateCondition(k6, v1alpha1.CloudPLZTestRun, metav1.ConditionFalse)
150+
151+
log.Info("Changing stage of TestRun status to initialized")
152+
153+
k6.GetStatus().Stage = "initialized"
154+
if updateHappened, err := r.UpdateStatus(ctx, k6, log); err != nil {
155+
return ctrl.Result{}, err
156+
} else if updateHappened {
157+
return ctrl.Result{}, nil
158+
}
159+
}
160+
143161
log.Info("Changing stage of TestRun status to initialization")
144162
k6.GetStatus().Stage = "initialization"
145163

0 commit comments

Comments
 (0)