Skip to content

Commit

Permalink
Reuse datavolumes already found in listMatchingDataVolumes for increa…
Browse files Browse the repository at this point in the history
…sed consistency between sync and updateStatus

Signed-off-by: Bartosz Rybacki <[email protected]>
  • Loading branch information
brybacki committed Nov 26, 2020
1 parent 4edc28a commit c8bc909
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/virt-controller/watch/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,12 @@ func (c *VMIController) handleSyncDataVolumes(vmi *virtv1.VirtualMachineInstance
pvcInterface, pvcExists, _ := c.pvcInformer.GetStore().GetByKey(fmt.Sprintf("%s/%s", vmi.Namespace, volume.VolumeSource.PersistentVolumeClaim.ClaimName))
if pvcExists {
pvc := pvcInterface.(*k8sv1.PersistentVolumeClaim)
populated, err := cdiv1.IsPopulated(pvc, dataVolumeByNameFunc(c.dataVolumeInformer))
populated, err := cdiv1.IsPopulated(pvc, dataVolumeByNameFunc(c.dataVolumeInformer, dataVolumes))
if err != nil {
return false, false, &syncErrorImpl{fmt.Errorf("Error determining if PVC %s is ready %v", pvc.Name, err), FailedDataVolumeImportReason}
}
if !populated {
waitsForFirstConsumer, err := cdiv1.IsWaitForFirstConsumerBeforePopulating(pvc, dataVolumeByNameFunc(c.dataVolumeInformer))
waitsForFirstConsumer, err := cdiv1.IsWaitForFirstConsumerBeforePopulating(pvc, dataVolumeByNameFunc(c.dataVolumeInformer, dataVolumes))
if err != nil {
return false, false, &syncErrorImpl{fmt.Errorf("Error determining if PVC %s is ready %v", pvc.Name, err), FailedDataVolumeImportReason}
}
Expand All @@ -713,8 +713,13 @@ func (c *VMIController) handleSyncDataVolumes(vmi *virtv1.VirtualMachineInstance
return ready, wffc, nil
}

func dataVolumeByNameFunc(dataVolumeInformer cache.SharedIndexInformer) func(name string, namespace string) (*cdiv1.DataVolume, error) {
func dataVolumeByNameFunc(dataVolumeInformer cache.SharedIndexInformer, dataVolumes []*cdiv1.DataVolume) func(name string, namespace string) (*cdiv1.DataVolume, error) {
return func(name, namespace string) (*cdiv1.DataVolume, error) {
for _, dataVolume := range dataVolumes {
if dataVolume.Name == name && dataVolume.Namespace == namespace {
return dataVolume, nil
}
}
dv, exists, _ := dataVolumeInformer.GetStore().GetByKey(fmt.Sprintf("%s/%s", namespace, name))
if !exists {
return nil, fmt.Errorf("Unable to find datavolume %s/%s", namespace, name)
Expand Down

0 comments on commit c8bc909

Please sign in to comment.