diff --git a/README.md b/README.md index e8e6e975..e47316c4 100644 --- a/README.md +++ b/README.md @@ -509,4 +509,4 @@ make delete ## See also -- [Running distributed k6 tests on Kubernetes](https://k6.io/blog/running-distributed-tests-on-k8s/) +- [Running distributed k6 tests on Kubernetes](https://k6.io/blog/running-distributed-tests-on-k8s/) \ No newline at end of file diff --git a/api/v1alpha1/k6_types.go b/api/v1alpha1/k6_types.go index 4af00fa4..22a6f594 100644 --- a/api/v1alpha1/k6_types.go +++ b/api/v1alpha1/k6_types.go @@ -114,7 +114,7 @@ type K6Configmap struct { //TODO: cleanup pre-execution? // Cleanup allows for automatic cleanup of resources post execution -// +kubebuilder:validation:Enum=post +// +kubebuilder:validation:Enum=post;whenOk;whenFailed type Cleanup string // Stage describes which stage of the test execution lifecycle our runners are in diff --git a/bundle.yaml b/bundle.yaml index 4e407c42..10a5ed7f 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -50,6 +50,8 @@ spec: cleanup: enum: - post + - whenOk + - whenFailed type: string initializer: properties: diff --git a/config/crd/bases/k6.io_k6s.yaml b/config/crd/bases/k6.io_k6s.yaml index f6f5a524..76953fce 100644 --- a/config/crd/bases/k6.io_k6s.yaml +++ b/config/crd/bases/k6.io_k6s.yaml @@ -44,6 +44,8 @@ spec: cleanup: enum: - post + - whenOk + - whenFailed type: string initializer: properties: diff --git a/controllers/k6_controller.go b/controllers/k6_controller.go index af7ee257..2238c0d7 100644 --- a/controllers/k6_controller.go +++ b/controllers/k6_controller.go @@ -261,7 +261,10 @@ func (r *K6Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re case "error", "finished": // delete if configured - if k6.Spec.Cleanup == "post" { + if (k6.Spec.Cleanup == "post") || + (k6.Status.Stage == "error" && k6.Spec.Cleanup == "whenFailed") || + (k6.Status.Stage == "finished" && k6.Spec.Cleanup == "whenOk") { + log.Info("Cleaning up all resources") r.Delete(ctx, k6) }