Skip to content

Commit d71a929

Browse files
authored
DV Recreated with Wrong Status (#3912)
* Add check during updateStatus that prevents DVs from updating its status from a PVC that is marked for deletion Signed-off-by: dsanatar <[email protected]> * add unit test to make sure PVCs marked for deletion do not update the status of existing DVs Signed-off-by: dsanatar <[email protected]> --------- Signed-off-by: dsanatar <[email protected]>
1 parent 239edac commit d71a929

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

pkg/controller/datavolume/controller-base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ func (r *ReconcilerBase) updateStatus(req reconcile.Request, phaseSync *statusPh
916916

917917
if shouldSetDataVolumePending(pvc, dataVolumeCopy) {
918918
dataVolumeCopy.Status.Phase = cdiv1.Pending
919-
} else if pvc != nil {
919+
} else if pvc != nil && pvc.DeletionTimestamp == nil {
920920
dataVolumeCopy.Status.ClaimName = pvc.Name
921921

922922
phase := pvc.Annotations[cc.AnnPodPhase]

pkg/controller/datavolume/import-controller_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,44 @@ var _ = Describe("All DataVolume Tests", func() {
14661466
Expect(readyCondition.Message).To(Equal(""))
14671467
})
14681468

1469+
It("Should not use PVC to update status if PVC is marked for deletion", func() {
1470+
dv := NewImportDataVolume("test-dv")
1471+
annotations := map[string]string{
1472+
AnnPopulatedFor: "test-dv",
1473+
AnnPodPhase: string(corev1.PodSucceeded),
1474+
}
1475+
pvc := CreatePvc("test-dv", metav1.NamespaceDefault, annotations, nil)
1476+
// Set finalizer so PVC is not removed when Delete is called
1477+
pvc.Finalizers = append(pvc.Finalizers, "test-finalizer")
1478+
1479+
reconciler = createImportReconciler(dv, pvc)
1480+
_, err := reconciler.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-dv", Namespace: metav1.NamespaceDefault}})
1481+
Expect(err).ToNot(HaveOccurred())
1482+
1483+
By("Marking PVC for deletion")
1484+
err = reconciler.client.Delete(context.TODO(), pvc)
1485+
Expect(err).ToNot(HaveOccurred())
1486+
1487+
By("Resetting DV to Pending phase")
1488+
pendingStatus := cdiv1.Pending
1489+
dv = &cdiv1.DataVolume{}
1490+
err = reconciler.client.Get(context.TODO(), types.NamespacedName{Name: "test-dv", Namespace: metav1.NamespaceDefault}, dv)
1491+
Expect(err).ToNot(HaveOccurred())
1492+
dv.Status.Phase = pendingStatus
1493+
err = reconciler.client.Status().Update(context.TODO(), dv)
1494+
Expect(err).ToNot(HaveOccurred())
1495+
1496+
By("Calling updateStatus")
1497+
_, err = reconciler.updateStatus(getReconcileRequest(dv), nil, reconciler)
1498+
Expect(err).ToNot(HaveOccurred())
1499+
1500+
By("Checking DV did not inherit new status from PVC")
1501+
dv = &cdiv1.DataVolume{}
1502+
err = reconciler.client.Get(context.TODO(), types.NamespacedName{Name: "test-dv", Namespace: metav1.NamespaceDefault}, dv)
1503+
Expect(err).ToNot(HaveOccurred())
1504+
Expect(dv.Status.Phase).To(Equal(pendingStatus))
1505+
})
1506+
14691507
It("Should switch to paused if pod phase is succeeded but a checkpoint is set", func() {
14701508
reconciler = createImportReconciler(NewImportDataVolume("test-dv"))
14711509
_, err := reconciler.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-dv", Namespace: metav1.NamespaceDefault}})

0 commit comments

Comments
 (0)