Skip to content

Commit 0d83b46

Browse files
committed
fix(vmop): check target disk errors only in container creating
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
1 parent ab23371 commit 0d83b46

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

images/virtualization-artifact/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
5151
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5252
github.com/deckhouse/3p-kubevirt/staging/src/kubevirt.io/api v0.0.0-20260403095053-aefa74c02fee h1:FL3Sn9OL9HZZX01vWiO6t6ps8nkxH+AOilBp+Rdp6iU=
5353
github.com/deckhouse/3p-kubevirt/staging/src/kubevirt.io/api v0.0.0-20260403095053-aefa74c02fee/go.mod h1:wGZLfRa/b4w/V/hakmfcK0CmrAZGfpj+jN7BMt0s19E=
54+
github.com/deckhouse/3p-kubevirt/staging/src/kubevirt.io/api v0.0.0-20260403154920-301347b413ce h1:b6I/SUcA30j2wcOBBERbN20cKARaDAHNtSzP4XB6kgg=
55+
github.com/deckhouse/3p-kubevirt/staging/src/kubevirt.io/api v0.0.0-20260403154920-301347b413ce/go.mod h1:wGZLfRa/b4w/V/hakmfcK0CmrAZGfpj+jN7BMt0s19E=
5456
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20250226105106-176cd3afcdd5 h1:PsN1E0oxC/+4zdA977txrqUCuObFL3HAuu5Xnud8m8c=
5557
github.com/deckhouse/deckhouse/pkg/log v0.0.0-20250226105106-176cd3afcdd5/go.mod h1:Mk5HRzkc5pIcDIZ2JJ6DPuuqnwhXVkb3you8M8Mg+4w=
5658
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ func (h LifecycleHandler) calculateMigrationProgress(
649649
}
650650

651651
func (h LifecycleHandler) getTargetPodDiskError(ctx context.Context, pod *corev1.Pod) (string, bool) {
652-
if pod == nil || pod.Status.Phase != corev1.PodPending || pod.DeletionTimestamp != nil {
652+
if pod == nil || !isContainerCreating(pod) || pod.DeletionTimestamp != nil {
653653
return "", false
654654
}
655655

@@ -703,6 +703,18 @@ func (h LifecycleHandler) getTargetPod(ctx context.Context, mig *virtv1.VirtualM
703703
return nil, nil
704704
}
705705

706+
func isContainerCreating(pod *corev1.Pod) bool {
707+
if pod == nil || pod.Status.Phase != corev1.PodPending {
708+
return false
709+
}
710+
for _, cs := range pod.Status.ContainerStatuses {
711+
if cs.State.Waiting != nil && cs.State.Waiting.Reason == "ContainerCreating" {
712+
return true
713+
}
714+
}
715+
return false
716+
}
717+
706718
func isPodPendingUnschedulable(pod *corev1.Pod) bool {
707719
if pod == nil {
708720
return false

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,5 +830,46 @@ var _ = Describe("LifecycleHandler", func() {
830830
Expect(err).NotTo(HaveOccurred())
831831
Expect(reason).To(Equal(vmopcondition.ReasonTargetDiskError))
832832
})
833+
834+
It("should ignore target pod disk attach error when pod is not in ContainerCreating", func() {
835+
mig := newSimpleMigration("vmop-test", name)
836+
mig.UID = "migration-uid"
837+
mig.Status.Phase = virtv1.MigrationPreparingTarget
838+
839+
pod := &corev1.Pod{
840+
ObjectMeta: metav1.ObjectMeta{
841+
Namespace: namespace,
842+
Name: "target-pod",
843+
Labels: map[string]string{
844+
virtv1.AppLabel: "virt-launcher",
845+
virtv1.MigrationJobLabel: "migration-uid",
846+
},
847+
},
848+
Status: corev1.PodStatus{
849+
Phase: corev1.PodPending,
850+
ContainerStatuses: []corev1.ContainerStatus{
851+
{
852+
Name: "compute",
853+
State: corev1.ContainerState{Waiting: &corev1.ContainerStateWaiting{Reason: "ImagePullBackOff"}},
854+
},
855+
},
856+
},
857+
}
858+
event := &corev1.Event{
859+
ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "disk-event"},
860+
InvolvedObject: corev1.ObjectReference{Name: "target-pod", Kind: "Pod", Namespace: namespace},
861+
Type: corev1.EventTypeWarning,
862+
Reason: "FailedAttachVolume",
863+
Message: "failed to attach disk",
864+
}
865+
866+
fakeClient, err := testutil.NewFakeClientWithObjects(mig, pod, event)
867+
Expect(err).NotTo(HaveOccurred())
868+
869+
h := LifecycleHandler{client: fakeClient}
870+
reason, _, err := h.getInProgressReasonAndMessage(ctx, mig)
871+
Expect(err).NotTo(HaveOccurred())
872+
Expect(reason).To(Equal(vmopcondition.ReasonTargetPreparing))
873+
})
833874
})
834875
})

0 commit comments

Comments
 (0)