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

Add DevWorkspace Pruner (operator-lib/prune package) #1402

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

akurinnoy
Copy link
Contributor

@akurinnoy akurinnoy commented Mar 18, 2025

What does this PR do?

This pull request adds a new controller that prunes (removes) DevWorkspaces based on these rules:

  • DevWorkspaces that haven't been started for a specific period are considered inactive. This period is configurable.
  • The pruning behavior (enable/disable, retention time, cron schedule, dry-run mode) is configured via the DevWorkspaceOperatorConfig (DWOC) resource.
  • The pruning process is scheduled using a cron library, allowing for flexible configuration of the pruning frequency.
  • A dry-run mode is supported, allowing administrators to preview the pruning actions without actually deleting any resources.

What issues does this PR fix or reference?

resolves #1376

Is it tested? How?

  1. Deploy the operator with this new code.
  2. Ensure that the DevWorksapceOperatorConfig initially does not have pruning enabled by default
    • there is no CleanupCronJob section in the config.workspace section of the DWOC.
    • or, if there is the CleanupCronJob section, ensure that enable: false.
  3. Patch the DevWorkspaceOperatorConfig to enable pruning and set parameters:
kubectl patch DevWorkspaceOperatorConfig devworkspace-operator-config \
-n devworkspace-controller \
--type=merge \
-p '{"config": {"workspace": {"cleanupCronJob": {"enable": true, "dryRun": true, "retainTime": 60, "schedule": "* * * * *"}}}}'
  1. Create several DevWorkspaces. Some should be started, and some should not be started.
  2. Wait for the cron schedule to trigger the pruning - at least 1 minute.
  3. Check logs and verify that the correct DevWorkspaces are identified but not deleted in dry-run mode.
  4. Disable dry-run mode and verify that all eligible DevWorkspaces are actually deleted:
kubectl patch DevWorkspaceOperatorConfig devworkspace-operator-config \
-n devworkspace-controller \
--type=merge \
-p '{"config": {"workspace": {"cleanupCronJob": {"dryRun": false }}}}'

PR Checklist

  • E2E tests pass (when PR is ready, comment /test v8-devworkspace-operator-e2e, v8-che-happy-path to trigger)
    • v8-devworkspace-operator-e2e: DevWorkspace e2e test
    • v8-che-happy-path: Happy path for verification integration with Che

Copy link

openshift-ci bot commented Mar 18, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link

openshift-ci bot commented Mar 18, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: akurinnoy
Once this PR has been reviewed and has the lgtm label, please assign dkwon17 for approval. For more information see the Code Review Process.

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

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

@akurinnoy akurinnoy changed the title Operator lib prune package Add DevWorkspace Pruner (operator-lib/prune package) Mar 18, 2025
@akurinnoy akurinnoy force-pushed the operator-lib-prune-package branch 9 times, most recently from 4a44124 to 4dc83c6 Compare March 25, 2025 14:05
@akurinnoy akurinnoy force-pushed the operator-lib-prune-package branch from 4dc83c6 to cdbf388 Compare March 27, 2025 11:57
@akurinnoy akurinnoy force-pushed the operator-lib-prune-package branch from 78b0e3d to 3218747 Compare April 1, 2025 09:04
@akurinnoy akurinnoy marked this pull request as ready for review April 1, 2025 13:29
@akurinnoy akurinnoy requested a review from ibuziuk as a code owner April 1, 2025 13:29
@openshift-ci openshift-ci bot requested a review from dkwon17 April 1, 2025 13:29
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.

Add a devworkspace pruner to the DevWorkspace Operator
2 participants