Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow clean K6 object when test has failed or finished OK #276

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
2 changes: 1 addition & 1 deletion api/v1alpha1/k6_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
cleanup:
enum:
- post
- whenOk
- whenFailed
type: string
initializer:
properties:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/k6.io_k6s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ spec:
cleanup:
enum:
- post
- whenOk
- whenFailed
type: string
initializer:
properties:
Expand Down
5 changes: 4 additions & 1 deletion controllers/k6_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading