Skip to content

Conversation

@Dsanatar
Copy link
Collaborator

@Dsanatar Dsanatar commented Sep 17, 2025

What this PR does / why we need it:

When a DV that is apart of a VM's DVTemplate gets deleted occasionally during the recreation, the new DV will be seen to immediately have status of Succeeded with Progress at 100% and then will eventually switch back to Pending. This is due to a race condition where the associated PVC is not deleted/cleaned up in time for when the new DV goes to update its status. Since the new DV will see the old PVC is bound, it will immediately update it's first status to Succeeded.

Added a new check during updateStatus() to prevent DVs from using PVCs that have a DeletionTimeStamp

Release note:

Check for PVC DeletionTimeStamp before updating DV status

its status from a PVC that is marked for deletion

Signed-off-by: dsanatar <[email protected]>
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/XS labels Sep 17, 2025
Copy link
Member

@alromeros alromeros left a comment

Choose a reason for hiding this comment

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

Good catch! Testing this would be great but seems tricky to do.
/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 18, 2025
@akalenyu
Copy link
Collaborator

Good catch! Testing this would be great but seems tricky to do. /lgtm

I think we should be able to supply the erroneous state to a fake reconciler in a unit test, tbh, that would also make me feel a little better about this change as I don't completely understand the scenario

@alromeros
Copy link
Member

Good catch! Testing this would be great but seems tricky to do. /lgtm

I think we should be able to supply the erroneous state to a fake reconciler in a unit test, tbh, that would also make me feel a little better about this change as I don't completely understand the scenario

Agree but isolating this logic might not be straightforward, and also there're no utests for this file. The behavior is racy but maybe it's worth having a functest that deletes the pvc and ensures the DV completes nicely to ensure there're no weird behaviors in between?

@alromeros
Copy link
Member

/hold
Let's discuss first the testing options

@kubevirt-bot kubevirt-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 18, 2025
@akalenyu
Copy link
Collaborator

Good catch! Testing this would be great but seems tricky to do. /lgtm

I think we should be able to supply the erroneous state to a fake reconciler in a unit test, tbh, that would also make me feel a little better about this change as I don't completely understand the scenario

Agree but isolating this logic might not be straightforward, and also there're no utests for this file. The behavior is racy but maybe it's worth having a functest that deletes the pvc and ensures the DV completes nicely to ensure there're no weird behaviors in between?

That's prone to flakes, I'd unit test it with a pinpointed state identified to be wrong
We can use any of the unit test suites for controller that piggyback on the controller base, so import for example

@kubevirt-bot kubevirt-bot added size/M and removed lgtm Indicates that a PR is ready to be merged. size/XS labels Sep 22, 2025
@coveralls
Copy link

coveralls commented Sep 22, 2025

Coverage Status

coverage: 59.153%. remained the same
when pulling b39fb7d on Dsanatar:dv-recreated-status
into 2b04a3d on kubevirt:main.

@alromeros
Copy link
Member

/unhold
Looks great!
/lgtm

@kubevirt-bot kubevirt-bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Sep 23, 2025
Comment on lines 1503 to 1507
// Reset the DV status phase
newPhase := cdiv1.Pending
dv.Status.Phase = newPhase
err = reconciler.client.Status().Update(context.TODO(), dv)
Expect(err).ToNot(HaveOccurred())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Which entity would be causing this in a "real" setup?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem spawns from when a deleted DV from a VM's DVTemplate is recreated. Here I am trying to emulate that behavior of the "new" DV by just resetting the status and making sure it doesn't inherit a new status from it's associated PVC that is in the process of deletion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, maybe we can reduce the test to that then? IOW are all the setup steps really needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea good point, I can give that a go and see.

@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 26, 2025
Copy link
Collaborator

@akalenyu akalenyu left a comment

Choose a reason for hiding this comment

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

I believe you can further reduce this to passing the entire state to the fake reconciler, but up to you
/approve

Comment on lines 1483 to 1485
// Set finalizer so PVC is not removed when Delete is called
pvc.Finalizers = append(pvc.Finalizers, "test-finalizer")
err = reconciler.client.Update(context.TODO(), pvc)
Expect(err).ToNot(HaveOccurred())

// Mark PVC for deletion
err = reconciler.client.Delete(context.TODO(), pvc)
Expect(err).ToNot(HaveOccurred())
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't have to use the client to setup the state, you can just pass the objects in the target state to createImportReconciler

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: akalenyu

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

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 28, 2025
update the status of existing DVs

Signed-off-by: dsanatar <[email protected]>
@alromeros
Copy link
Member

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 8, 2025
@kubevirt-bot kubevirt-bot merged commit d71a929 into kubevirt:main Oct 8, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants