Skip to content

Commit

Permalink
reduce complexity in progress gathering from virt-v2v
Browse files Browse the repository at this point in the history
Signed-off-by: Arik Hadas <[email protected]>
  • Loading branch information
ahadas committed Dec 24, 2023
1 parent 8ee0892 commit a8f7fd8
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions pkg/controller/plan/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1481,52 +1481,54 @@ func (r *Migration) updateConversionProgress(vm *plan.VMStatus, step *plan.Step)
return
}

if pod != nil {
switch pod.Status.Phase {
case core.PodSucceeded:
step.MarkCompleted()
step.Progress.Completed = step.Progress.Total
case core.PodFailed:
step.MarkCompleted()
step.AddError("Guest conversion failed. See pod logs for details.")
default:
el9, el9Err := r.Context.Plan.VSphereUsesEl9VirtV2v()
if el9Err != nil {
err = el9Err
return
}
if el9 {
err = r.updateConversionProgressEl9(pod, step)
if err != nil {
// Just log it. Missing progress is not fatal.
log.Error(err, "Failed to update conversion progress")
err = nil
return
}
}
}
} else {
if pod == nil {
step.MarkCompleted()
step.AddError("Guest conversion pod not found")
return
}

switch pod.Status.Phase {
case core.PodSucceeded:
step.MarkCompleted()
step.Progress.Completed = step.Progress.Total
case core.PodFailed:
step.MarkCompleted()
step.AddError("Guest conversion failed. See pod logs for details.")
default:
if pod.Status.PodIP == "" {
// we get the progress from the pod and we cannot connect to the pod without PodIP
break
}

el9, el9Err := r.Context.Plan.VSphereUsesEl9VirtV2v()
switch {
case el9Err == nil && el9:
if progressErr := r.updateConversionProgressEl9(pod, step); progressErr != nil {
// Just log it. Missing progress is not fatal.
log.Error(err, "Failed to update conversion progress")
}
case el9Err != nil:
err = el9Err
return
}
}

return
}

func (r *Migration) updateConversionProgressEl9(pod *core.Pod, step *plan.Step) (err error) {
if pod.Status.PodIP == "" {
return
}

var diskRegex = regexp.MustCompile(`v2v_disk_transfers\{disk_id="(\d+)"\} (\d{1,3}\.?\d*)`)
url := fmt.Sprintf("http://%s:2112/metrics", pod.Status.PodIP)
resp, err := http.Get(url)
if err != nil {
if strings.Contains(err.Error(), "connection refused") {
return nil
}
switch {
case err == nil:
defer resp.Body.Close()
case strings.Contains(err.Error(), "connection refused"):
return nil
default:
return
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
return
Expand Down

0 comments on commit a8f7fd8

Please sign in to comment.