Skip to content

Commit

Permalink
Fix DataImportCron import DataVolume creation when last import is not…
Browse files Browse the repository at this point in the history
… found (kubevirt#3072)

* Fix DIC DV creation when last import is not found

The `imports` local variable was not updated correctly, and later
referenced, so another reconcile was required for the DV to be created.

Fixes CNV-33973

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Fix DV controller Watch comment

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

---------

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
  • Loading branch information
arnongilboa authored Jan 19, 2024
1 parent 338bafe commit 25dcbab
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/controller/dataimportcron-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ func (r *DataImportCronReconciler) update(ctx context.Context, dataImportCron *c
importSucceeded = true
} else {
if len(imports) > 0 {
dataImportCron.Status.CurrentImports = imports[1:]
imports = imports[1:]
dataImportCron.Status.CurrentImports = imports
}
updateDataImportCronCondition(dataImportCron, cdiv1.DataImportCronProgressing, corev1.ConditionFalse, "No current import", noImport)
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/controller/dataimportcron-controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,38 @@ var _ = Describe("All DataImportCron Tests", func() {
Entry("empty schedule", emptySchedule, "should succeed with an empty schedule"),
)

It("Should recreate DataVolume if the last import was deleted", func() {
cron = newDataImportCron(cronName)
cron.Annotations[AnnSourceDesiredDigest] = testDigest
reconciler = createDataImportCronReconciler(cron)

_, err := reconciler.Reconcile(context.TODO(), cronReq)
Expect(err).ToNot(HaveOccurred())
err = reconciler.client.Get(context.TODO(), cronKey, cron)
Expect(err).ToNot(HaveOccurred())

imports := cron.Status.CurrentImports
Expect(imports).ToNot(BeEmpty())
dvName := imports[0].DataVolumeName
Expect(dvName).ToNot(BeEmpty())

dv := &cdiv1.DataVolume{}
err = reconciler.client.Get(context.TODO(), dvKey(dvName), dv)
Expect(err).ToNot(HaveOccurred())

err = reconciler.client.Delete(context.TODO(), dv)
Expect(err).ToNot(HaveOccurred())
err = reconciler.client.Get(context.TODO(), dvKey(dvName), dv)
Expect(err).To(HaveOccurred())
Expect(k8serrors.IsNotFound(err)).To(BeTrue())

_, err = reconciler.Reconcile(context.TODO(), cronReq)
Expect(err).ToNot(HaveOccurred())

err = reconciler.client.Get(context.TODO(), dvKey(dvName), dv)
Expect(err).ToNot(HaveOccurred())
})

It("Should not create DV if PVC exists on DesiredDigest update; Should update DIC and DAS, and GC LRU PVCs", func() {
const nPVCs = 3
var (
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/datavolume/controller-base.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ func addDataVolumeControllerCommonWatches(mgr manager.Manager, dataVolumeControl
}
}

// FIXME: Consider removing this Watch. Not sure it's needed anymore as PVCs are Pending in this case.
// Watch for SC updates and reconcile the DVs waiting for default SC
// Relevant only when the DV StorageSpec has no AccessModes set and no matching StorageClass yet, so PVC cannot be created (test_id:9922)
if err := dataVolumeController.Watch(&source.Kind{Type: &storagev1.StorageClass{}}, handler.EnqueueRequestsFromMapFunc(
func(obj client.Object) (reqs []reconcile.Request) {
dvList := &cdiv1.DataVolumeList{}
Expand All @@ -321,6 +321,7 @@ func addDataVolumeControllerCommonWatches(mgr manager.Manager, dataVolumeControl
}

// Watch for PV updates to reconcile the DVs waiting for available PV
// Relevant only when the DV StorageSpec has no AccessModes set and no matching StorageClass yet, so PVC cannot be created (test_id:9924,9925)
if err := dataVolumeController.Watch(&source.Kind{Type: &corev1.PersistentVolume{}}, handler.EnqueueRequestsFromMapFunc(
func(obj client.Object) (reqs []reconcile.Request) {
pv := obj.(*corev1.PersistentVolume)
Expand Down

0 comments on commit 25dcbab

Please sign in to comment.