Skip to content

Allow resuming and suspending tests by changing a live TestRun resource #457

@LCaparelli

Description

@LCaparelli

This feature request was initially described as a bugfix due to a misunderstanding of the spec.paused field.

Initial report

Brief summary

While the operator correctly propagates the configuration as part of the flags for the runner:

paused := true
if k6.GetSpec().Paused != "" {
paused, _ = strconv.ParseBool(k6.GetSpec().Paused)
}
if paused {
command = append(command, "--paused")
}

It makes no checks prior to creating the starter:

case "initialized":
return CreateJobs(ctx, log, k6, r)
case "created":
return StartJobs(ctx, log, k6, r)

Neither functions above make any checks regarding spec.paused AFAICT.

Since the starter job always unpauses the the runner:

func NewStartContainer(hostnames []string, image string, imagePullPolicy corev1.PullPolicy, command []string, env []corev1.EnvVar, securityContext corev1.SecurityContext) corev1.Container {
req, _ := json.Marshal(
types.StatusAPIRequest{
Data: types.StatusAPIRequestData{
Attributes: types.StatusAPIRequestDataAttributes{
Paused: false,
},
ID: "default",
Type: "status",
},
})
var parts []string
for _, hostname := range hostnames {
parts = append(parts, fmt.Sprintf("curl --retry 3 -X PATCH -H 'Content-Type: application/json' http://%s:6565/v1/status -d '%s'", hostname, req))
}

We end up with spec.paused being ignored (technically, partially ignored because the --paused flag does get added to the runner arguments, but in practice it always unpauses due to how the starter behaves).

Suggested implementation

We might solve this by just adding an if statement when the status is "created", guarding the StartJobs function:

	case "created":
                if k6.IsPaused() {
                        // nothing to do. When the user updates spec.paused a new reconciliation will trigger and we'll check again
                        return ctrl.Result{}, nil 
                }
		return StartJobs(ctx, log, k6, r)

Of course, this implies that changing spec.paused after the test has started continues to have no effect, but that seems sensible to me.

k6-operator version or image

0.0.16

Helm chart version (if applicable)

No response

TestRun / PrivateLoadZone YAML

Anything with spec.paused set to 'true'.

Other environment details (if applicable)

No response

Steps to reproduce the problem

  1. Create a TestRun with spec.paused set to 'true'
  2. Wait for jobs to run

Expected behaviour

Runner does not start the test before I set spec.paused to 'false' or null.

Actual behaviour

Starter behaves exactly as if spec.paused was set to 'false' or null, and immediately starts the runner.

Feature Description

It would be nice if we could edit a live TestRun resource to suspend or resume it, similarly to what Kubernetes does with Jobs.

Suggested Solution (optional)

Add a spec.suspend field that controls whether to run the starter job or not.

Already existing or connected issues / PRs (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions