@@ -110,11 +110,6 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {
110110 return nil
111111 }
112112
113- if vmiMigration .Status .MigrationState .Completed {
114- klog .V (3 ).Infof ("VirtualMachineInstanceMigration %s migration state is completed, skipping" , key )
115- return nil
116- }
117-
118113 vmi , err := c .config .KubevirtClient .VirtualMachineInstance (namespace ).Get (context .TODO (), vmiMigration .Spec .VMIName , metav1.GetOptions {})
119114 if err != nil {
120115 utilruntime .HandleError (fmt .Errorf ("failed to get VMI by name %s: %w" , vmiMigration .Spec .VMIName , err ))
@@ -123,7 +118,7 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {
123118
124119 // use VirtualMachineInstance's MigrationState because VirtualMachineInstanceMigration's MigrationState is not updated until migration finished
125120 var srcNodeName , targetNodeName string
126- if vmi .Status .MigrationState != nil {
121+ if vmi .Status .MigrationState != nil && vmi . Status . MigrationState . MigrationUID == vmiMigration . UID {
127122 klog .Infof ("current vmiMigration %s status %s, target Node %s, source Node %s, target Pod %s, source Pod %s" , key ,
128123 vmiMigration .Status .Phase ,
129124 vmi .Status .MigrationState .TargetNode ,
@@ -133,7 +128,17 @@ func (c *Controller) handleAddOrUpdateVMIMigration(key string) error {
133128 srcNodeName = vmi .Status .MigrationState .SourceNode
134129 targetNodeName = vmi .Status .MigrationState .TargetNode
135130 } else {
136- klog .Infof ("current vmiMigration %s status %s, vmi MigrationState is nil" , key , vmiMigration .Status .Phase )
131+ if vmi .Status .MigrationState != nil {
132+ klog .Infof ("current vmiMigration %s status %s, vmi MigrationState is stale" , key , vmiMigration .Status .Phase )
133+ } else {
134+ klog .Infof ("current vmiMigration %s status %s, vmi MigrationState is nil" , key , vmiMigration .Status .Phase )
135+ }
136+ // If we're at an end state and the vmi migration state is stale or nil, we're probably looking at an old migration
137+ // either way, we can't proceed since we don't have the source and target nodes for resetting the migrate options
138+ if vmiMigration .Status .Phase == kubevirtv1 .MigrationSucceeded || vmiMigration .Status .Phase == kubevirtv1 .MigrationFailed {
139+ klog .V (3 ).Infof ("VirtualMachineInstanceMigration %s migration state is Succeeded/Failed but VMI migration state is stale or nil, skipping" , key )
140+ return nil
141+ }
137142 }
138143
139144 lsps , err := c .OVNNbClient .ListNormalLogicalSwitchPorts (c .config .EnableExternalVpc , map [string ]string {"pod" : fmt .Sprintf ("%s/%s" , vmi .Namespace , vmi .Name )})
0 commit comments