Skip to content

Conversation

annakhvorostianova
Copy link

@annakhvorostianova annakhvorostianova commented Sep 12, 2025

Closes #397

Summary

  • Adds spec.ttlSecondsAfterFinished to TestRun to control automatic cleanup of Jobs created by a test run, mirroring Kubernetes Job TTL behavior.
  • Propagates the TTL value to initializer, runner, and starter Jobs so they are garbage‑collected by the Kubernetes TTL controller after finishing.

Behavior

  • Nil: when ttlSecondsAfterFinished is omitted, no TTL is set on Jobs (no automatic cleanup if cleanup: 'post' is not set).
  • Zero: 0 means Jobs are eligible for cleanup immediately after finishing (actual deletion depends on controller timing).
  • Scope: TTL applies to Jobs and their Pods only; it does not delete the TestRun CR or Services.
  • Interaction with cleanup: spec.cleanup: "post" still deletes the TestRun at finish, cascading deletion of Jobs immediately (bypassing TTL). Use TTL without "post" when you want Jobs/Pods retained temporarily.

Example

  • In TestRun.spec:
    - ttlSecondsAfterFinished: 600

Steps to test it:

  1. Create a kind cluster.
  2. Build and load the image:
 IMG_NAME=k6operator IMG_TAG=feat-397 make docker-build
kind load docker-image k6operator:feat-397
  1. Deploy operator:
      - IMG_NAME=k6operator IMG_TAG=feat-397 make deploy
  1. Check controller logs:
      - kubectl -n k6-operator-system logs deploy/k6-operator-controller-manager -f
  1. Create a test namespace and apply the sample TestRun with TTL:
kubectl create ns k6-tests
kubectl -n k6-tests apply -f config/samples/k6_v1alpha1_configmap.yaml
  1. Confirm the TestRun:
kubectl -n k6-tests get testruns
kubectl -n k6-tests describe testrun testrun-sample
  1. Observe Jobs and TTL behavior
# List Jobs created by the TestRun:
kubectl -n k6-tests get jobs -l app=k6,k6_cr=testrun-sample
# Verify the TTL is set on Jobs:
kubectl -n k6-tests get job <job-name> -o yaml | rg ttlSecondsAfterFinished
# Wait for the test to finish (status “finished” on TestRun).
# After ~600s from completion, Jobs should be removed automatically by the TTL controller:
kubectl -n k6-tests get jobs (should be empty after TTL expires)

@CLAassistant
Copy link

CLAassistant commented Sep 12, 2025

CLA assistant check
All committers have signed the CLA.

@annakhvorostianova annakhvorostianova marked this pull request as ready for review September 12, 2025 10:17
@yorugac
Copy link
Collaborator

yorugac commented Sep 28, 2025

Hi @annakhvorostianova, thanks for the PR. FYI, I've closed #397 as it is a duplicate of an older issue, #260.

I have some doubts about how this feature should be designed ATM and will share summary in the issue shortly. Please feel free to respond there: let's keep the design discussion in the issue and the code discussion in the PR. Basically, AFAIK the use cases this TTL field is supposed to target, it may be that we don't need to add this field to TestRun CRD as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce ttlSecondsAfterFinished to TestRun
3 participants