Skip to content

Commit 8d1c208

Browse files
authored
fix(core): clarify migration timeout failure message (#2209)
Clarify the VM migration failure condition message when KubeVirt reports that the target pod was unschedulable and deleted after the scheduling timeout. Instead of exposing the raw low-level message from KubeVirt, the controller now returns a user-friendly condition message that explains the actual reason: no suitable node was found for placing the target VM within the timeout period. Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
1 parent a4d45a5 commit 8d1c208

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

images/virtualization-artifact/pkg/controller/vmop/migration/internal/handler/lifecycle.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func getMessageByMigrationFailedReason(mig *virtv1.VirtualMachineInstanceMigrati
508508
case virtv1.VirtualMachineInstanceMigrationFailedReasonVMIDoesNotExist, virtv1.VirtualMachineInstanceMigrationFailedReasonVMIIsShutdown:
509509
return "VirtualMachine is stopped"
510510
default:
511-
return cond.Message
511+
return humanizeMigrationFailedMessage(cond.Message)
512512
}
513513
}
514514

@@ -678,6 +678,14 @@ func (h LifecycleHandler) forgetProgress(vmop *v1alpha2.VirtualMachineOperation)
678678
h.progressStrategy.Forget(vmop.UID)
679679
}
680680

681+
func humanizeMigrationFailedMessage(message string) string {
682+
if strings.Contains(message, "unschedulable target pod") && strings.Contains(message, "timeout period expiration") {
683+
return "No available nodes were found to place the target VM within the timeout period"
684+
}
685+
686+
return message
687+
}
688+
681689
func (h LifecycleHandler) getTargetPod(ctx context.Context, mig *virtv1.VirtualMachineInstanceMigration) (*corev1.Pod, error) {
682690
selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
683691
MatchLabels: map[string]string{

images/virtualization-artifact/pkg/controller/vmop/migration/internal/handler/lifecycle_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,4 +902,31 @@ var _ = Describe("LifecycleHandler", func() {
902902
Expect(reason).To(Equal(vmopcondition.ReasonTargetPreparing))
903903
})
904904
})
905+
906+
DescribeTable("humanizeMigrationFailedMessage", func(message, expected string) {
907+
Expect(humanizeMigrationFailedMessage(message)).To(Equal(expected))
908+
},
909+
Entry(
910+
"should humanize unschedulable target pod timeout message",
911+
"unschedulable target pod \"virt-launcher-bastion-demo-z7hcs\" was deleted due to timeout period expiration",
912+
"No available nodes were found to place the target VM within the timeout period",
913+
),
914+
Entry(
915+
"should keep other messages as is",
916+
"some other migration failure",
917+
"some other migration failure",
918+
),
919+
)
920+
921+
It("should use humanized message for migration failed condition", func() {
922+
mig := newSimpleMigration("test", name)
923+
mig.Status.Conditions = []virtv1.VirtualMachineInstanceMigrationCondition{{
924+
Type: virtv1.VirtualMachineInstanceMigrationFailed,
925+
Status: corev1.ConditionTrue,
926+
Reason: "SomeOtherReason",
927+
Message: "unschedulable target pod \"virt-launcher-bastion-demo-z7hcs\" was deleted due to timeout period expiration",
928+
}}
929+
930+
Expect(getMessageByMigrationFailedReason(mig)).To(Equal("No available nodes were found to place the target VM within the timeout period"))
931+
})
905932
})

0 commit comments

Comments
 (0)