Skip to content

feat: add dry run option for cleanup subcommand#21

Merged
mrhillsman merged 2 commits into
opdev:mainfrom
OchiengEd:cleanup_dry_run
Feb 23, 2026
Merged

feat: add dry run option for cleanup subcommand#21
mrhillsman merged 2 commits into
opdev:mainfrom
OchiengEd:cleanup_dry_run

Conversation

@OchiengEd

@OchiengEd OchiengEd commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

This commit adds the --dry-run flag to the cleanup subcommand to allow users to review the impacts of the cleanup action before they run it.

Below is output of the validation of work done:

➜  virtwork git:(cleanup_dry_run) ./bin/virtwork run
Namespace virtwork ensured
Service virtwork-iperf3-server created
Secret virtwork-cpu-0-cloudinit created
Secret virtwork-database-0-cloudinit created
Secret virtwork-disk-0-cloudinit created
Secret virtwork-memory-0-cloudinit created
Secret virtwork-network-server-0-cloudinit created
Secret virtwork-network-client-0-cloudinit created
VM virtwork-network-server-0 created
VM virtwork-network-client-0 created
VM virtwork-memory-0 created
VM virtwork-disk-0 created
VM virtwork-cpu-0 created
VM virtwork-database-0 created
Waiting for 6 VMs to become ready (timeout: 10m0s)...
VM virtwork-network-client-0: VMI not yet created, retrying...
VM virtwork-database-0: VMI not yet created, retrying...
VM virtwork-memory-0: VMI not yet created, retrying...
VM virtwork-disk-0: VMI not yet created, retrying...
VM virtwork-network-server-0: VMI not yet created, retrying...
VM virtwork-cpu-0: VMI not yet created, retrying...
All 6 VMs ready
==================================================
Deployment Summary
==================================================
Run ID:       78a05c8f-bf43-4e38-929e-e90abd9cb863
Namespace:    virtwork
VMs created:  6
Services:     1
Secrets:      6
Image:        quay.io/containerdisks/fedora:41
==================================================
➜  virtwork git:(cleanup_dry_run) oc -n virtwork get po
NAME                                            READY   STATUS    RESTARTS   AGE
virt-launcher-virtwork-cpu-0-kgk7r              3/3     Running   0          2m30s
virt-launcher-virtwork-database-0-79hbj         3/3     Running   0          2m30s
virt-launcher-virtwork-disk-0-xrgl5             3/3     Running   0          2m30s
virt-launcher-virtwork-memory-0-q54bb           3/3     Running   0          2m30s
virt-launcher-virtwork-network-client-0-w7755   3/3     Running   0          2m30s
virt-launcher-virtwork-network-server-0-cbbkz   3/3     Running   0          2m30s
➜  virtwork git:(cleanup_dry_run) ./bin/virtwork cleanup --dry-run 
Cleanup complete: 6 VMs deleted, 1 services deleted, 6 secrets deleted
➜  virtwork git:(cleanup_dry_run) oc -n virtwork get po           
NAME                                            READY   STATUS    RESTARTS   AGE
virt-launcher-virtwork-cpu-0-kgk7r              3/3     Running   0          3m
virt-launcher-virtwork-database-0-79hbj         3/3     Running   0          3m
virt-launcher-virtwork-disk-0-xrgl5             3/3     Running   0          3m
virt-launcher-virtwork-memory-0-q54bb           3/3     Running   0          3m
virt-launcher-virtwork-network-client-0-w7755   3/3     Running   0          3m
virt-launcher-virtwork-network-server-0-cbbkz   3/3     Running   0          3m
➜  virtwork git:(cleanup_dry_run) ./bin/virtwork cleanup          
Cleanup complete: 6 VMs deleted, 1 services deleted, 6 secrets deleted
➜  virtwork git:(cleanup_dry_run) oc -n virtwork get po 
No resources found in virtwork namespace.
➜  virtwork git:(cleanup_dry_run) 

Closes #5

@exe-prow-github-app

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: OchiengEd

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

// Individual deletion failures are recorded but do not abort the operation.
// If deleteNamespace is true, the namespace itself is deleted as the final step.
func CleanupAll(ctx context.Context, c client.Client, namespace string, deleteNamespace bool, runID string) (*CleanupResult, error) {
func CleanupAll(ctx context.Context, c client.Client, cfg *config.Config, deleteNamespace bool, runID string) (*CleanupResult, error) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In lieu of adding an argument for dry run, I chose to pass in the *config.Config from which we can determine the namespace and if dry run is set to true.


// Setup delete options
opts := []client.DeleteOption{}
if cfg.DryRun {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When dry run is true, controller runtime delete will be called with the dry run all option.

@mrhillsman

Copy link
Copy Markdown
Contributor

@OchiengEd thx for this. just one addition. there is no indication in the output it is a dry run.

❯ ./virtwork cleanup --dry-run
Cleanup complete: 6 VMs deleted, 1 services deleted, 6 secrets deleted
❯ ./virtwork cleanup
Cleanup complete: 6 VMs deleted, 1 services deleted, 6 secrets deleted

@OchiengEd

Copy link
Copy Markdown
Contributor Author

Noted. I will look into that.

Signed-off-by: Edmund Ochieng <ochienged@gmail.com>
@OchiengEd

Copy link
Copy Markdown
Contributor Author

All done.

➜  virtwork git:(cleanup_dry_run) ./bin/virtwork cleanup --dry-run           
--- Dry Run ---
Cleanup complete: 6 VMs deleted, 1 services deleted, 6 secrets deleted
➜  virtwork git:(cleanup_dry_run) 

@mrhillsman
mrhillsman merged commit 0a8e49a into opdev:main Feb 23, 2026
1 check failed
@OchiengEd
OchiengEd deleted the cleanup_dry_run branch February 23, 2026 22:35
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.

[Feature]: Add --dry-run flag to the cleanup subcommand

2 participants