forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubevirt#2028 from ksimon1/feature/clusterCPUModel
add default cluster cpu model
- Loading branch information
Showing
8 changed files
with
197 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ import ( | |
"kubevirt.io/kubevirt/tests" | ||
) | ||
|
||
const kubevirtConfig = "kubevirt-config" | ||
|
||
func newCirrosVMI() *v1.VirtualMachineInstance { | ||
return tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n") | ||
} | ||
|
@@ -632,6 +634,91 @@ var _ = Describe("[rfe_id:273][crit:high][vendor:[email protected]][level:compon | |
|
||
}) | ||
|
||
Context("with default cpu model", func() { | ||
var cfgMap *k8sv1.ConfigMap | ||
var originalData map[string]string | ||
var options metav1.GetOptions | ||
var defaultCPUModelKey = "default-cpu-model" | ||
var defaultCPUModel = "Conroe" | ||
var vmiCPUModel = "SandyBridge" | ||
|
||
//store old kubevirt-config | ||
BeforeEach(func() { | ||
cfgMap, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Get(kubevirtConfig, options) | ||
Expect(err).ToNot(HaveOccurred()) | ||
originalData = cfgMap.Data | ||
}) | ||
|
||
//replace new kubevirt-config with old config | ||
AfterEach(func() { | ||
cfgMap, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Get(kubevirtConfig, options) | ||
Expect(err).ToNot(HaveOccurred()) | ||
cfgMap.Data = originalData | ||
_, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Update(cfgMap) | ||
Expect(err).ToNot(HaveOccurred()) | ||
time.Sleep(5 * time.Second) | ||
}) | ||
|
||
It("should set default cpu model when vmi doesn't have it set", func() { | ||
cfgMap, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Get(kubevirtConfig, options) | ||
Expect(err).ToNot(HaveOccurred(), "Expect config map to be loaded without error") | ||
|
||
cfgMap.Data[defaultCPUModelKey] = defaultCPUModel | ||
_, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Update(cfgMap) | ||
Expect(err).ToNot(HaveOccurred(), "Expect config map to be updated without error") | ||
|
||
time.Sleep(5 * time.Second) | ||
|
||
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n") | ||
|
||
_, err = virtClient.VirtualMachineInstance(vmi.Namespace).Create(vmi) | ||
Expect(err).ToNot(HaveOccurred(), "Should create VMI") | ||
tests.WaitForSuccessfulVMIStart(vmi) | ||
|
||
curVMI, err := virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred(), "Should get VMI") | ||
Expect(curVMI.Spec.Domain.CPU.Model).To(Equal("Conroe"), "Expected default CPU model") | ||
|
||
}) | ||
|
||
It("should not set default cpu model when vmi has it set", func() { | ||
cfgMap, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Get(kubevirtConfig, options) | ||
Expect(err).ToNot(HaveOccurred(), "Expect config map to be loaded without error") | ||
|
||
cfgMap.Data[defaultCPUModelKey] = defaultCPUModel | ||
|
||
_, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Update(cfgMap) | ||
Expect(err).ToNot(HaveOccurred(), "Expect config map to be updated without error") | ||
|
||
time.Sleep(5 * time.Second) | ||
|
||
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n") | ||
vmi.Spec.Domain.CPU = &v1.CPU{ | ||
Model: vmiCPUModel, | ||
} | ||
_, err = virtClient.VirtualMachineInstance(vmi.Namespace).Create(vmi) | ||
Expect(err).ToNot(HaveOccurred(), "Should create VMI") | ||
tests.WaitForSuccessfulVMIStart(vmi) | ||
|
||
curVMI, err := virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred(), "Should get VMI") | ||
Expect(curVMI.Spec.Domain.CPU.Model).To(Equal(vmiCPUModel), "Expected vmi CPU model") | ||
|
||
}) | ||
|
||
It("should not set cpu model when vmi does not have it set and default cpu model is not set", func() { | ||
vmi := tests.NewRandomVMIWithEphemeralDiskAndUserdata(tests.ContainerDiskFor(tests.ContainerDiskCirros), "#!/bin/bash\necho 'hello'\n") | ||
_, err = virtClient.VirtualMachineInstance(vmi.Namespace).Create(vmi) | ||
Expect(err).ToNot(HaveOccurred(), "Should create VMI") | ||
|
||
tests.WaitForSuccessfulVMIStart(vmi) | ||
|
||
curVMI, err := virtClient.VirtualMachineInstance(vmi.Namespace).Get(vmi.Name, &metav1.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred(), "Should get VMI") | ||
Expect(curVMI.Spec.Domain.CPU).To(BeNil(), "Expected CPU to be nil") | ||
}) | ||
}) | ||
|
||
Context("with node feature discovery", func() { | ||
|
||
var options metav1.GetOptions | ||
|
@@ -648,20 +735,17 @@ var _ = Describe("[rfe_id:273][crit:high][vendor:[email protected]][level:compon | |
originalLabels = node.GetObjectMeta().GetLabels() | ||
|
||
options = metav1.GetOptions{} | ||
cfgMap, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Get("kubevirt-config", options) | ||
cfgMap, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Get(kubevirtConfig, options) | ||
Expect(err).ToNot(HaveOccurred()) | ||
originalFeatureGates = cfgMap.Data[virtconfig.FeatureGatesKey] | ||
cfgMap.Data[virtconfig.FeatureGatesKey] = virtconfig.CPUNodeDiscoveryGate | ||
_, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Update(cfgMap) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
//FIXME improve the detection if virt-controller already received the config-map change | ||
time.Sleep(time.Millisecond * 500) | ||
|
||
time.Sleep(5 * time.Second) | ||
}) | ||
|
||
AfterEach(func() { | ||
cfgMap, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Get("kubevirt-config", options) | ||
cfgMap, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Get(kubevirtConfig, options) | ||
Expect(err).ToNot(HaveOccurred()) | ||
cfgMap.Data[virtconfig.FeatureGatesKey] = originalFeatureGates | ||
_, err = virtClient.CoreV1().ConfigMaps(namespaceKubevirt).Update(cfgMap) | ||
|
@@ -673,8 +757,7 @@ var _ = Describe("[rfe_id:273][crit:high][vendor:[email protected]][level:compon | |
_, err = virtClient.CoreV1().Nodes().Update(n) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
//FIXME improve the detection if virt-controller already received the config-map change | ||
time.Sleep(time.Millisecond * 500) | ||
time.Sleep(5 * time.Second) | ||
}) | ||
|
||
It("[test_id:1639]the vmi with cpu.model matching a nfd label on a node should be scheduled", func() { | ||
|
@@ -1339,7 +1422,7 @@ var _ = Describe("[rfe_id:273][crit:high][vendor:[email protected]][level:compon | |
func shouldUseEmulation(virtClient kubecli.KubevirtClient) bool { | ||
useEmulation := false | ||
options := metav1.GetOptions{} | ||
cfgMap, err := virtClient.CoreV1().ConfigMaps(tests.KubeVirtInstallNamespace).Get("kubevirt-config", options) | ||
cfgMap, err := virtClient.CoreV1().ConfigMaps(tests.KubeVirtInstallNamespace).Get(kubevirtConfig, options) | ||
if err == nil { | ||
val, ok := cfgMap.Data["debug.useEmulation"] | ||
useEmulation = ok && (val == "true") | ||
|