diff --git a/api/v1alpha1/k6conditions.go b/api/v1alpha1/k6conditions.go index a21c782d..5ea39624 100644 --- a/api/v1alpha1/k6conditions.go +++ b/api/v1alpha1/k6conditions.go @@ -10,6 +10,7 @@ import ( ) const ( + InitializerSkipped = "InitializerSkipped" // 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 diff --git a/api/v1alpha1/testrun_types.go b/api/v1alpha1/testrun_types.go index b14f0b0a..49e4c374 100644 --- a/api/v1alpha1/testrun_types.go +++ b/api/v1alpha1/testrun_types.go @@ -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"` @@ -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 +} diff --git a/config/crd/bases/k6.io_testruns.yaml b/config/crd/bases/k6.io_testruns.yaml index 5143b366..6cfe59f9 100644 --- a/config/crd/bases/k6.io_testruns.yaml +++ b/config/crd/bases/k6.io_testruns.yaml @@ -558,6 +558,9 @@ spec: type: string type: object type: object + disabled: + default: false + type: boolean env: items: properties: @@ -2593,6 +2596,9 @@ spec: type: string type: object type: object + disabled: + default: false + type: boolean env: items: properties: @@ -4649,6 +4655,9 @@ spec: type: string type: object type: object + disabled: + default: false + type: boolean env: items: properties: diff --git a/config/samples/k6_v1alpha1_testrun_initializer_disabled.yaml b/config/samples/k6_v1alpha1_testrun_initializer_disabled.yaml new file mode 100644 index 00000000..630e7351 --- /dev/null +++ b/config/samples/k6_v1alpha1_testrun_initializer_disabled.yaml @@ -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 diff --git a/docs/crd-generated.md b/docs/crd-generated.md index 0d681b50..29fc102c 100644 --- a/docs/crd-generated.md +++ b/docs/crd-generated.md @@ -869,6 +869,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo are set, the values in SecurityContext take precedence.
false + + disabled + boolean + +
+
+ Default: false
+ + false env []object @@ -9822,6 +9831,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo are set, the values in SecurityContext take precedence.
false + + disabled + boolean + +
+
+ Default: false
+ + false env []object @@ -18797,6 +18815,15 @@ Some fields are present in both SecurityContext and PodSecurityContext. When bo are set, the values in SecurityContext take precedence.
false + + disabled + boolean + +
+
+ Default: false
+ + false env []object diff --git a/internal/controller/testrun_controller.go b/internal/controller/testrun_controller.go index 3ce2584d..88b25de6 100644 --- a/internal/controller/testrun_controller.go +++ b/internal/controller/testrun_controller.go @@ -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() { + 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" diff --git a/pkg/types/conditions.go b/pkg/types/conditions.go index a93f6ecf..1f958279 100644 --- a/pkg/types/conditions.go +++ b/pkg/types/conditions.go @@ -66,6 +66,9 @@ func SetIfNewer(cond *[]metav1.Condition, } var reasons = map[string]string{ + "InitializerSkippedTrue": "InitializerWasSkipped", + "InitializerSkippedFalse": "InitializerWasRequested", + "TestRunRunningUnknown": "TestRunPreparation", "TestRunRunningTrue": "TestRunRunningTrue", "TestRunRunningFalse": "TestRunRunningFalse",