Skip to content

Commit

Permalink
Use getDataVolumeFromCache() across VM controller
Browse files Browse the repository at this point in the history
Signed-off-by: Zvi Cahana <[email protected]>
  • Loading branch information
zcahana committed Nov 2, 2021
1 parent 9db7d72 commit d62b722
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions pkg/virt-controller/watch/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,14 @@ func (c *VMController) listDataVolumesForVM(vm *virtv1.VirtualMachine) ([]*cdiv1

for _, template := range vm.Spec.DataVolumeTemplates {
// get DataVolume from cache for each templated dataVolume
dvKey := controller.NamespacedKey(vm.Namespace, template.Name)
obj, exists, err := c.dataVolumeInformer.GetStore().GetByKey(dvKey)

dv, err := c.getDataVolumeFromCache(vm.Namespace, template.Name)
if err != nil {
return dataVolumes, err
} else if !exists {
} else if dv == nil {
continue
}

dataVolumes = append(dataVolumes, obj.(*cdiv1.DataVolume))
dataVolumes = append(dataVolumes, dv)
}
return dataVolumes, nil
}
Expand Down Expand Up @@ -522,28 +520,26 @@ func (c *VMController) hasDataVolumeErrors(vm *virtv1.VirtualMachine) bool {
continue
}

dvKey := controller.NamespacedKey(vm.Namespace, volume.DataVolume.Name)
dvObj, exists, err := c.dataVolumeInformer.GetStore().GetByKey(dvKey)
dv, err := c.getDataVolumeFromCache(vm.Namespace, volume.DataVolume.Name)
if err != nil {
log.Log.Object(vm).Errorf("Error fetching DataVolume %s: %v", dvKey, err)
log.Log.Object(vm).Errorf("Error fetching DataVolume %s: %v", volume.DataVolume.Name, err)
continue
}
if !exists {
if dv == nil {
continue
}

dv := dvObj.(*cdiv1.DataVolume)

if dv.Status.Phase == cdiv1.Failed {
log.Log.Object(vm).Errorf("DataVolume %s is in Failed phase", dvKey)
log.Log.Object(vm).Errorf("DataVolume %s is in Failed phase", volume.DataVolume.Name)
return true
}

dvRunningCond := controller.NewDataVolumeConditionManager().GetCondition(dv, cdiv1.DataVolumeRunning)
if dvRunningCond != nil &&
dvRunningCond.Status == k8score.ConditionFalse &&
dvRunningCond.Reason == "Error" {
log.Log.Object(vm).Errorf("DataVolume %s importer has stopped running due to an error: %v", dvKey, dvRunningCond.Message)
log.Log.Object(vm).Errorf("DataVolume %s importer has stopped running due to an error: %v",
volume.DataVolume.Name, dvRunningCond.Message)
return true
}
}
Expand Down

0 comments on commit d62b722

Please sign in to comment.