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

feat: added DevWorkspace pruner #1397

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

akurinnoy
Copy link
Contributor

@akurinnoy akurinnoy commented Mar 7, 2025

What does this PR do?

This PR adds a DevWorkspace pruner that uses a CronJob to periodically identify and delete DevWorkspaces that have been inactive for a specified duration.

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 DevWorkspaceOperatorConfig initially does not have pruning enabled by default:
    • there is no CleanupCronJob section in the config.workspace section of the DWOC
    • or, if a CleanupCronJob is present in config.workspace, verify that enable: false.
  3. Create several DevWorkspaces in various states: started and stopped.
  4. Patch the DevWorkspaceOperatorConfig to enable pruning and set parameters:
    kubectl patch DevWorkspaceOperatorConfig devworkspace-operator-config \
      -n <operator-namespace> \
      --type=merge \
      -p '{"config": {"workspace": {"cleanupCronJob": {"enable": true, "retainTime": 60, "image": "image-registry.openshift-image-registry.svc:5000/openshift/cli:latest"}}}}'
    • Make sure to use an image": "..." with the correct oc image path on your cluster.
  5. Patch the CronJob to schedule the pruning every 1 minute:
    kubectl patch CronJob devworkspace-pruner \
      -n <operator-namespace> \
      --type=merge \
      -p '{"spec":{"schedule":"* * * * *"}}'
  6. Wait for the CronJob to run (at least 1 minute).
  7. Verify that the correct DevWorkspaces are deleted:
    • Use kubectl get devworkspaces -A to check which DevWorkspaces are present. Only DevWorkspaces that should not be deleted should exist.
    • Inspect the CronJob's logs (kubectl logs -l job-name=<pruner-cronjob-name> -n <operator-namespace>) to confirm that the pruner script is running and identifying the correct DevWorkspaces for deletion.
    • Inspect the ConfigMap and confirm that the script exists there
  8. Disable pruning and verify the CronJob is suspended:
    • Patch the DevWorkspaceOperatorConfig to disable pruning:
      kubectl patch DevWorkspaceOperatorConfig devworkspace-operator-config \
        -n <operator-namespace> \
        --type=merge \
        -p '{"config": {"workspace": {"cleanupCronJob": {"enable": false}}}}'
    • Verify that the CronJob's suspend field is set to true:
      kubectl get cronjob devworkspace-pruner -n <operator-namespace> -o jsonpath='{.spec.suspend}'

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 7, 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 7, 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 self-assigned this Mar 7, 2025
@akurinnoy akurinnoy force-pushed the devworkspace-pruner branch 2 times, most recently from 5425e6f to cfae5e7 Compare March 11, 2025 15:27
@akurinnoy akurinnoy force-pushed the devworkspace-pruner branch 4 times, most recently from db6bd9b to 85eb245 Compare March 25, 2025 07:14
@akurinnoy akurinnoy force-pushed the devworkspace-pruner branch from 85eb245 to 54d6ac3 Compare March 25, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a devworkspace pruner to the DevWorkspace Operator
2 participants