Skip to content

Commit

Permalink
Do more logging during the import
Browse files Browse the repository at this point in the history
Add log messages to better track what the importer is doing and to better isolate errors if necessary.

Related to: harvester/harvester#6512

Signed-off-by: Volker Theile <[email protected]>
  • Loading branch information
votdev authored and ibrokethecloud committed Sep 11, 2024
1 parent bda1e62 commit 409740f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 10 deletions.
68 changes: 61 additions & 7 deletions pkg/controllers/migration/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,61 @@ func (h *virtualMachineHandler) OnVirtualMachineChange(_ string, vmObj *migratio

vm := vmObj.DeepCopy()
switch vm.Status.Status {
case "": // run preflight checks and make vm ready for import
case "":
// run preflight checks and make vm ready for import
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Info("Running preflight checks ...")
return h.reconcilePreFlightChecks(vm)
case migration.SourceReady: //vm migration is valid and ready. trigger migration specific import
case migration.SourceReady:
// vm migration is valid and ready. trigger migration specific import
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Info("Importing client disk images ...")
return h.runVirtualMachineExport(vm)
case migration.DisksExported: // prepare and add routes for disks to be used for VirtualMachineImage CRD
case migration.DisksExported:
// prepare and add routes for disks to be used for VirtualMachineImage CRD
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Info("Creating VM images ...")
return h.reconcileDiskImageStatus(vm)
case migration.DiskImagesSubmitted:
// check and update disk image status based on VirtualMachineImage watches
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Info("Evaluating VM images ...")
err := h.reconcileVMIStatus(vm)
if err != nil {
return vm, err
}

newStatus := evaluateDiskImportStatus(vm.Status.DiskImportStatus)
if newStatus == nil {
return vm, nil
}
vm.Status.Status = *newStatus
return h.importVM.UpdateStatus(vm)
case migration.DiskImagesFailed:
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Error("Failed to import client disk images. Try again ...")
return h.triggerResubmit(vm)
case migration.DiskImagesReady:
// create VM to use the VirtualMachineObject
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Info("Creating VM instances ...")
err := h.createVirtualMachine(vm)
if err != nil {
return vm, err
Expand All @@ -125,15 +157,32 @@ func (h *virtualMachineHandler) OnVirtualMachineChange(_ string, vmObj *migratio
return h.importVM.UpdateStatus(vm)
case migration.VirtualMachineCreated:
// wait for VM to be running using a watch on VM's
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Info("Checking VM instances ...")
return h.reconcileVirtualMachineStatus(vm)
case migration.VirtualMachineRunning:
logrus.Infof("vm %s in namespace %v imported successfully", vm.Name, vm.Namespace)
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Info("The VM was imported successfully")
return vm, h.tidyUpObjects(vm)
case migration.VirtualMachineInvalid:
logrus.Infof("vm %s in namespace %v has an invalid spec", vm.Name, vm.Namespace)
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Error("The VM import spec is invalid")
return vm, nil
case migration.VirtualMachineMigrationFailed:
logrus.Infof("vm migration failed for %s in namespace %s", vm.Name, vm.Namespace)
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Error("The VM import has failed")
return vm, nil
}

Expand Down Expand Up @@ -188,6 +237,11 @@ func (h *virtualMachineHandler) triggerExport(vm *migration.VirtualMachineImport

// power off machine
if !util.ConditionExists(vm.Status.ImportConditions, migration.VirtualMachinePoweringOff, v1.ConditionTrue) {
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
}).Info("Powering off client VM ...")
err = vmo.PowerOffVirtualMachine(vm)
if err != nil {
return fmt.Errorf("error in poweroff call: %v", err)
Expand Down
9 changes: 6 additions & 3 deletions pkg/source/openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,17 @@ func (c *Client) ExportVirtualMachine(vm *migration.VirtualMachineImport) error
return err
}

logrus.Info(volObj)
logrus.WithFields(logrus.Fields{
"name": vm.Name,
"namespace": vm.Namespace,
"spec.virtualMachineName": vm.Spec.VirtualMachineName,
"volume": volObj,
}).Info("Attempting to create new image from volume")

if err := volumes.WaitForStatus(c.storageClient, volObj.ID, "available", pollingTimeout); err != nil {
return fmt.Errorf("timeout waiting for volumes %v to become available: %v", volObj.ID, err)
}

logrus.Info("attempting to create new image from volume")

volImage, err := volumeactions.UploadImage(c.storageClient, volObj.ID, volumeactions.UploadImageOpts{
ImageName: fmt.Sprintf("import-controller-%s-%d", vm.Spec.VirtualMachineName, i),
DiskFormat: "qcow2",
Expand Down

0 comments on commit 409740f

Please sign in to comment.