Update VMI status' MigrationConfiguration on every migration
@@ -671,11 +671,17 @@ func (c *MigrationController) handleTargetPodHandoff(migration *virtv1.VirtualMa
}
}
- err := c.matchMigrationPolicy(vmiCopy, c.clusterConfig.GetMigrationConfiguration())
+ clusterMigrationConfigs := c.clusterConfig.GetMigrationConfiguration()
+ err := c.matchMigrationPolicy(vmiCopy, clusterMigrationConfigs)
if err != nil {
return fmt.Errorf("failed to match migration policy: %v", err)
}
+ if !c.isMigrationPolicyMatched(vmiCopy) {
+ clusterMigrationConfigsCopy := *clusterMigrationConfigs
+ vmiCopy.Status.MigrationState.MigrationConfiguration = &clusterMigrationConfigsCopy
+ }
+
err = c.patchVMI(vmi, vmiCopy)
if err != nil {
c.recorder.Eventf(migration, k8sv1.EventTypeWarning, FailedHandOverPodReason, fmt.Sprintf("Failed to set MigrationStat in VMI status. :%v", err))
@@ -1602,3 +1608,12 @@ func (c *MigrationController) matchMigrationPolicy(vmi *virtv1.VirtualMachineIns
return nil
}
+
+func (c *MigrationController) isMigrationPolicyMatched(vmi *virtv1.VirtualMachineInstance) bool {
+ if vmi == nil {
+ return false
+ }
+
+ migrationPolicyName := vmi.Status.MigrationState.MigrationPolicyName
+ return migrationPolicyName != nil && *migrationPolicyName != ""
+}
