Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/k6conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

const (
InitializerSkipped = "InitializerSkipped"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is set but never checked: what is the point of it then?
PS I don't say yet that we definitely won't need it, but right now it doesn't look like it.

// TestRunRunning indicates if the test run is currently running.
// - if empty / Unknown, it's any stage before k6 resume (starter)
// - if False, it's after all runners have finished successfully or with error
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/testrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type PodMetadata struct {
}

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

return &client.ListOptions{LabelSelector: selector, Namespace: k6.NamespacedName().Namespace}
}

func (k6 *TestRun) IsInitializerDisabled() bool {
if k6.GetSpec().Initializer == nil {
return false
}
return k6.GetSpec().Initializer.Disabled
}
9 changes: 9 additions & 0 deletions config/crd/bases/k6.io_testruns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ spec:
type: string
type: object
type: object
disabled:
default: false
type: boolean
env:
items:
properties:
Expand Down Expand Up @@ -2593,6 +2596,9 @@ spec:
type: string
type: object
type: object
disabled:
default: false
type: boolean
env:
items:
properties:
Expand Down Expand Up @@ -4649,6 +4655,9 @@ spec:
type: string
type: object
type: object
disabled:
default: false
type: boolean
env:
items:
properties:
Expand Down
13 changes: 13 additions & 0 deletions config/samples/k6_v1alpha1_testrun_initializer_disabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
name: k6-sample
spec:
parallelism: 4
initializer:
disabled: true
script:
configMap:
name: k6-test
file: test.js
27 changes: 27 additions & 0 deletions docs/crd-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo
are set, the values in SecurityContext take precedence.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>disabled</b></td>
<td>boolean</td>
<td>
<br/>
<br/>
<i>Default</i>: false<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#testrunspecinitializerenvindex">env</a></b></td>
<td>[]object</td>
Expand Down Expand Up @@ -9822,6 +9831,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo
are set, the values in SecurityContext take precedence.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>disabled</b></td>
<td>boolean</td>
<td>
<br/>
<br/>
<i>Default</i>: false<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#testrunspecrunnerenvindex">env</a></b></td>
<td>[]object</td>
Expand Down Expand Up @@ -18797,6 +18815,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo
are set, the values in SecurityContext take precedence.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>disabled</b></td>
<td>boolean</td>
<td>
<br/>
<br/>
<i>Default</i>: false<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#testrunspecstarterenvindex">env</a></b></td>
<td>[]object</td>
Expand Down
17 changes: 17 additions & 0 deletions internal/controller/testrun_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ func (r *TestRunReconciler) reconcile(ctx context.Context, req ctrl.Request, log
return ctrl.Result{}, err
}

// Not a clout test and initializer is set to disabled
// -> skip creating initializer job
if !isCloudTestRun(k6) && k6.IsInitializerDisabled() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to take into account the --out cloud argument only, not all Cloud tests. So if that argument is present, initializer.disabled is discarded.

log.Info("Initializer is disabled, skipping initialization step")
v1alpha1.UpdateCondition(k6, v1alpha1.InitializerSkipped, metav1.ConditionTrue)
v1alpha1.UpdateCondition(k6, v1alpha1.CloudTestRun, metav1.ConditionFalse)

log.Info("Changing stage of TestRun status to initialized")
k6.GetStatus().Stage = "initialized"
if updateHappened, err := r.UpdateStatus(ctx, k6, log); err != nil {
return ctrl.Result{}, err
} else if updateHappened {
return ctrl.Result{}, nil
}
}

v1alpha1.UpdateCondition(k6, v1alpha1.InitializerSkipped, metav1.ConditionFalse)
log.Info("Changing stage of TestRun status to initialization")
k6.GetStatus().Stage = "initialization"

Expand Down
3 changes: 3 additions & 0 deletions pkg/types/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func SetIfNewer(cond *[]metav1.Condition,
}

var reasons = map[string]string{
"InitializerSkippedTrue": "InitializerWasSkipped",
"InitializerSkippedFalse": "InitializerWasRequested",

"TestRunRunningUnknown": "TestRunPreparation",
"TestRunRunningTrue": "TestRunRunningTrue",
"TestRunRunningFalse": "TestRunRunningFalse",
Expand Down
Loading