Skip to content

Conversation

@AObuchow
Copy link
Collaborator

@AObuchow AObuchow commented May 9, 2022

What does this PR do?

When the common PVC is cleaned up after workspace deletion, a check occurs to see if other workspaces using the common or shared storage-class attribute exist in the same namespace (i.e. other workspaces are using the same shared PVC). If there are no workspaces using the shared PVC, then the PVC is marked for deletion.

What issues does this PR fix or reference?

Fix #826

Is it tested? How?

  • Create 2 or more workspaces using a shared PVC (eg. with the storage class set to async, common, or unset)
  • Ensure that the claim-devworkspace PVC is created
  • Delete all workspaces
  • Ensure that the claim-devworkspace PVC is deleted shortly afterwards.

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

@AObuchow AObuchow requested review from amisevsk and ibuziuk as code owners May 9, 2022 21:57
@openshift-ci
Copy link

openshift-ci bot commented May 9, 2022

Hi @AObuchow. Thanks for your PR.

I'm waiting for a devfile member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

}
return nil
} else {
return runCommonPVCCleanupJob(workspace, clusterAPI)
Copy link
Collaborator

Choose a reason for hiding this comment

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

In terms of balancing conditional branches, it probably makes sense to move this one up to the top, i.e. have

if totalWorkspaces > 1 {
  return runCommonPVCCleanupJob(workspace, clusterAPI)
} else {
  // delete PVC
}

Comment on lines 93 to 102
err = clusterAPI.Client.Delete(clusterAPI.Ctx, existingPVC)
if err != nil && !k8sErrors.IsNotFound(err) {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly here, need to handle the IsNotFound error case (it's not an error, the object has already been deleted).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh man, I was tired yesterday, ignore this one :D

Comment on lines 253 to 255
if workspace.Spec.Started {
started++
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If started isn't currently needed, may as well not count it for now.

if totalWorkspaces > 1 {
return runCommonPVCCleanupJob(workspace, clusterAPI)
} else {
existingPVC := &corev1.PersistentVolumeClaim{}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybe rename to sharedPVC?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Up to you :)

@AObuchow AObuchow requested a review from amisevsk May 10, 2022 16:03
if totalWorkspaces > 1 {
return runCommonPVCCleanupJob(workspace, clusterAPI)
} else {
existingPVC := &corev1.PersistentVolumeClaim{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Up to you :)

Comment on lines 93 to 102
err = clusterAPI.Client.Delete(clusterAPI.Ctx, existingPVC)
if err != nil && !k8sErrors.IsNotFound(err) {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh man, I was tired yesterday, ignore this one :D

Comment on lines 94 to 103
if err != nil && !k8sErrors.IsNotFound(err) {
if err != nil {
if k8sErrors.IsNotFound(err) {
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I apologize for my review here yesterday...

if err != nil && !k8sErrors.IsNotFound(err) {
  return err
}
return nil

and

err = clusterAPI.Client.Delete(clusterAPI.Ctx, existingPVC)
if err != nil {
	if k8sErrors.IsNotFound(err) {
		return nil
	}
	return err
}
return nil

are equivalent, with the original being a little cleaner. Sorry for the confusion!

Copy link
Collaborator

@amisevsk amisevsk left a comment

Choose a reason for hiding this comment

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

LGTM!

Tested on minikube.

Please autosquash commits before merging

@openshift-ci openshift-ci bot added the lgtm label May 11, 2022
Copy link
Contributor

@ibuziuk ibuziuk left a comment

Choose a reason for hiding this comment

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

LGTM, but looks like some of the commits are not signed (no Signed-off-by) which makes the PR check fail

Fix devfile#826

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
@AObuchow AObuchow force-pushed the optionally_delete_unused_shared_pvc branch from 24985c5 to 1378757 Compare May 18, 2022 15:05
@openshift-ci openshift-ci bot removed the lgtm label May 18, 2022
@AObuchow AObuchow requested a review from ibuziuk May 18, 2022 15:13
@openshift-ci
Copy link

openshift-ci bot commented May 24, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amisevsk, AObuchow, ibuziuk

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

The pull request process is described 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

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.

DWO should (optionally) delete shared PVCs when no workspaces are left that require it

3 participants