Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the populator pod on failure #637

Merged
merged 4 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions pkg/controller/plan/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ func (r *Migration) updateCopyProgress(vm *plan.VMStatus, step *plan.Step) (err
if r.Plan.Spec.Warm && len(importer.Status.ContainerStatuses) > 0 {
vm.Warm.Failures = int(importer.Status.ContainerStatuses[0].RestartCount)
}
if RestartLimitExceeded(importer) {
if restartLimitExceeded(importer) {
task.MarkedCompleted()
msg, _ := terminationMessage(importer)
task.AddError(msg)
Expand Down Expand Up @@ -1598,6 +1598,10 @@ func (r *Migration) updatePopulatorCopyProgress(vm *plan.VMStatus, step *plan.St
if err != nil {
return
}
populatorPods, err := r.kubevirt.getPopulatorPods()
if err != nil {
return
}

for _, pvc := range pvcs {
if _, ok := pvc.Annotations["lun"]; ok {
Expand All @@ -1616,6 +1620,11 @@ func (r *Migration) updatePopulatorCopyProgress(vm *plan.VMStatus, step *plan.St
continue
}

err = r.isPopulatorFailed(populatorPods, string(pvc.UID))
if err != nil {
return
}

if pvc.Status.Phase == core.ClaimBound {
task.Phase = Completed
task.Reason = TransferCompleted
Expand All @@ -1638,6 +1647,19 @@ func (r *Migration) updatePopulatorCopyProgress(vm *plan.VMStatus, step *plan.St
return
}

func (r *Migration) isPopulatorFailed(populatorPods []core.Pod, givenPvcId string) error {
liranr23 marked this conversation as resolved.
Show resolved Hide resolved
for _, pod := range populatorPods {
pvcId := strings.Split(pod.Name, "populate-")[1]
liranr23 marked this conversation as resolved.
Show resolved Hide resolved
if givenPvcId != pvcId {
continue
}
if pod.Status.Phase == core.PodFailed {
return fmt.Errorf("populator pod %s/%s failed for PVC %s. Please check the pod logs.", pod.Namespace, pod.Name, pvcId)
}
liranr23 marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}

func (r *Migration) setPopulatorPodsWithLabels(vm *plan.VMStatus, migrationID string) {
podList, err := r.kubevirt.GetPodsWithLabels(map[string]string{})
if err != nil {
Expand Down Expand Up @@ -1701,7 +1723,7 @@ func terminationMessage(pod *core.Pod) (msg string, ok bool) {
}

// Return whether the pod has failed and restarted too many times.
func RestartLimitExceeded(pod *core.Pod) (exceeded bool) {
func restartLimitExceeded(pod *core.Pod) (exceeded bool) {
if len(pod.Status.ContainerStatuses) == 0 {
return
}
Expand Down
1 change: 0 additions & 1 deletion pkg/lib-volume-populator/populator-machinery/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/plan",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/api/storage/v1:storage",
"//vendor/k8s.io/apimachinery/pkg/api/errors",
Expand Down
8 changes: 0 additions & 8 deletions pkg/lib-volume-populator/populator-machinery/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"time"

"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/plan"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -698,13 +697,6 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
if corev1.PodSucceeded != pod.Status.Phase {
if corev1.PodFailed == pod.Status.Phase {
c.recorder.Eventf(pvc, corev1.EventTypeWarning, reasonPodFailed, "Populator failed: %s", pod.Status.Message)
liranr23 marked this conversation as resolved.
Show resolved Hide resolved
// Delete failed pods so we can try again
if !plan.RestartLimitExceeded(pod) {
err = c.kubeClient.CoreV1().Pods(populatorNamespace).Delete(ctx, pod.Name, metav1.DeleteOptions{})
if err != nil {
return err
}
}
ahadas marked this conversation as resolved.
Show resolved Hide resolved
}
// We'll get called again later when the pod succeeds
return nil
Expand Down
Loading