Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.58]Fix evmcs hyperv vendor bug #8861

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/virt-controller/services/nodeselectorrenderer.go
Expand Up @@ -134,7 +134,7 @@ func hypervNodeSelectors(vmiFeatures *v1.Features) map[string]string {
}
}

if vmiFeatures.Hyperv.EVMCS != nil {
if vmiFeatures.Hyperv.EVMCS != nil && (vmiFeatures.Hyperv.EVMCS.Enabled == nil || (*vmiFeatures.Hyperv.EVMCS.Enabled) == true) {
nodeSelectors[v1.CPUModelVendorLabel+IntelVendorName] = "true"
}

Expand Down
26 changes: 16 additions & 10 deletions pkg/virt-controller/services/template_test.go
Expand Up @@ -1291,11 +1291,9 @@ var _ = Describe("Template", func() {
Expect(pod.Spec.NodeSelector).To(Not(HaveKey(ContainSubstring(v1.CPUModelVendorLabel))))
})

It("should add node selector for hyperv nodes if VMI requests hyperv features which depend on host kernel", func() {
DescribeTable("should add node selector for hyperv nodes if VMI requests hyperv features which depend on host kernel", func(EVMCSEnabled bool) {
config, kvInformer, svc = configFactory(defaultArch)
enableFeatureGate(virtconfig.HypervStrictCheckGate)

enabled := true
vmi := v1.VirtualMachineInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "testvmi",
Expand All @@ -1310,19 +1308,19 @@ var _ = Describe("Template", func() {
Features: &v1.Features{
Hyperv: &v1.FeatureHyperv{
SyNIC: &v1.FeatureState{
Enabled: &enabled,
Enabled: pointer.BoolPtr(true),
},
SyNICTimer: &v1.SyNICTimer{
Enabled: &enabled,
Enabled: pointer.BoolPtr(true),
},
Frequencies: &v1.FeatureState{
Enabled: &enabled,
Enabled: pointer.BoolPtr(true),
},
IPI: &v1.FeatureState{
Enabled: &enabled,
Enabled: pointer.BoolPtr(true),
},
EVMCS: &v1.FeatureState{
Enabled: &enabled,
Enabled: pointer.BoolPtr(EVMCSEnabled),
},
},
},
Expand All @@ -1337,8 +1335,16 @@ var _ = Describe("Template", func() {
Expect(pod.Spec.NodeSelector).Should(HaveKeyWithValue(NFD_KVM_INFO_PREFIX+"synictimer", "true"))
Expect(pod.Spec.NodeSelector).Should(HaveKeyWithValue(NFD_KVM_INFO_PREFIX+"frequencies", "true"))
Expect(pod.Spec.NodeSelector).Should(HaveKeyWithValue(NFD_KVM_INFO_PREFIX+"ipi", "true"))
Expect(pod.Spec.NodeSelector).Should(HaveKeyWithValue(v1.CPUModelVendorLabel+IntelVendorName, "true"))
})
if EVMCSEnabled {
Expect(pod.Spec.NodeSelector).Should(HaveKeyWithValue(v1.CPUModelVendorLabel+IntelVendorName, "true"))
} else {
Expect(pod.Spec.NodeSelector).ShouldNot(HaveKeyWithValue(v1.CPUModelVendorLabel+IntelVendorName, "true"))
}

},
Entry("intel vendor and vmx are required when EVMCS is enabled", true),
Entry("should not require intel vendor and vmx when EVMCS isn't enabled", false),
)

It("should not add node selector for hyperv nodes if VMI requests hyperv features which do not depend on host kernel", func() {
config, kvInformer, svc = configFactory(defaultArch)
Expand Down
6 changes: 6 additions & 0 deletions tests/hyperv_test.go
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
"time"

virtconfig "kubevirt.io/kubevirt/pkg/virt-config"

"kubevirt.io/kubevirt/pkg/virt-controller/watch/topology"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -250,6 +252,7 @@ var _ = Describe("[Serial][sig-compute] Hyper-V enlightenments", func() {
})

DescribeTable("the vmi with EVMCS HyperV feature should have correct HyperV and cpu features auto filled", func(featureState *v1.FeatureState) {
tests.EnableFeatureGate(virtconfig.HypervStrictCheckGate)
vmi := libvmi.NewCirros()
vmi.Spec.Domain.Features = &v1.Features{
Hyperv: &v1.FeatureHyperv{
Expand All @@ -264,11 +267,14 @@ var _ = Describe("[Serial][sig-compute] Hyper-V enlightenments", func() {
Expect(err).ToNot(HaveOccurred(), "Should get VMI")
Expect(vmi.Spec.Domain.Features.Hyperv.EVMCS).ToNot(BeNil(), "evmcs should not be nil")
Expect(vmi.Spec.Domain.CPU).ToNot(BeNil(), "cpu topology can't be nil")
pod := libvmi.GetPodByVirtualMachineInstance(vmi, vmi.Namespace)
if featureState.Enabled == nil || *featureState.Enabled == true {
Expect(vmi.Spec.Domain.Features.Hyperv.VAPIC).ToNot(BeNil(), "vapic should not be nil")
Expect(vmi.Spec.Domain.CPU.Features).To(HaveLen(1), "cpu topology has to contain 1 feature")
Expect(vmi.Spec.Domain.CPU.Features[0].Name).To(Equal(nodelabellerutil.VmxFeature), "vmx cpu feature should be requested")
Expect(pod.Spec.NodeSelector).Should(HaveKeyWithValue(v1.CPUModelVendorLabel+"Intel", "true"))
} else {
Expect(pod.Spec.NodeSelector).ShouldNot(HaveKeyWithValue(v1.CPUModelVendorLabel+"Intel", "true"))
Expect(vmi.Spec.Domain.Features.Hyperv.VAPIC).To(BeNil(), "vapic should be nil")
Expect(vmi.Spec.Domain.CPU.Features).To(BeEmpty())
}
Expand Down