Calculate selectors only for the initial Node to remeber the required features
@@ -598,7 +598,7 @@ func (c *MigrationController) createTargetPod(migration *virtv1.VirtualMachineIn
return err
}
- err = prepareNodeSelectorForHostCpuModel(node, templatePod)
+ err = prepareNodeSelectorForHostCpuModel(node, templatePod, sourcePod)
if err != nil {
return err
}
@@ -1580,9 +1580,19 @@ func (c *MigrationController) alertIfHostModelIsUnschedulable(vmi *virtv1.Virtua
}
}
-func prepareNodeSelectorForHostCpuModel(node *k8sv1.Node, pod *k8sv1.Pod) error {
+func prepareNodeSelectorForHostCpuModel(node *k8sv1.Node, pod *k8sv1.Pod, sourcePod *k8sv1.Pod) error {
var hostCpuModel, hostCpuModelLabelKey, hostModelLabelValue string
+ migratedAtLeastOnce := false
+ // if the vmi already migrated before it should include node selector that consider CPUModelLabel
+ for key, value := range sourcePod.Spec.NodeSelector {
+ if strings.Contains(key, virtv1.CPUFeatureLabel) || strings.Contains(key, virtv1.CPUModelLabel) {
+ pod.Spec.NodeSelector[key] = value
+ migratedAtLeastOnce = true
+ }
+ }
+
+ if !migratedAtLeastOnce {
for key, value := range node.Labels {
if strings.HasPrefix(key, virtv1.HostModelCPULabel) {
hostCpuModel = strings.TrimPrefix(key, virtv1.HostModelCPULabel)
@@ -1602,7 +1612,8 @@ func prepareNodeSelectorForHostCpuModel(node *k8sv1.Node, pod *k8sv1.Pod) error
hostCpuModelLabelKey = virtv1.HostModelCPULabel + hostCpuModel
pod.Spec.NodeSelector[hostCpuModelLabelKey] = hostModelLabelValue
- log.Log.Object(pod).Infof("host model label selector (\"%s\") defined for migration target pod", hostCpuModelLabelKey)
+ log.Log.Object(pod).Infof("cpu model label selector (\"%s\") defined for migration target pod", hostCpuModelLabelKey)
+ }
return nil
}
