Skip to content

Commit

Permalink
Merge pull request kubevirt#9163 from vladikr/fix_bz2166512
Browse files Browse the repository at this point in the history
bug: fix the requests/limits CPU number mismatch for VMs with isolatedEmulatorThread
  • Loading branch information
kubevirt-bot authored Feb 23, 2023
2 parents 3514283 + 458fe42 commit 3cc04f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/virt-controller/services/renderresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func WithCPUPinning(cpu *v1.CPU) ResourceRendererOption {
emulatorThreadCPU := resource.NewQuantity(1, resource.BinarySI)
limits := renderer.calculatedLimits[k8sv1.ResourceCPU]
limits.Add(*emulatorThreadCPU)
renderer.calculatedLimits[k8sv1.ResourceCPU] = limits
renderer.vmLimits[k8sv1.ResourceCPU] = limits
if cpuRequest, ok := renderer.vmRequests[k8sv1.ResourceCPU]; ok {
cpuRequest.Add(*emulatorThreadCPU)
renderer.vmRequests[k8sv1.ResourceCPU] = cpuRequest
Expand Down
19 changes: 14 additions & 5 deletions pkg/virt-controller/services/renderresources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,18 @@ var _ = Describe("Resource pod spec renderer", func() {

When("an isolated emulator thread is requested", func() {
cpuIsolatedEmulatorThreadOverhead := resource.MustParse("1000m")
userSpecifiedCPU := kubev1.ResourceList{kubev1.ResourceCPU: userCPURequest}
userSpecifiedCPURequest := kubev1.ResourceList{kubev1.ResourceCPU: userCPURequest}

It("requires an additional 1000m CPU, and an additional CPU is added to the limits", func() {
DescribeTable("requires an additional 1000m CPU, and an additional CPU is added to the limits", func(defineUserSpecifiedCPULimit bool) {

var userSpecifiedCPULimit kubev1.ResourceList

if defineUserSpecifiedCPULimit {
userSpecifiedCPULimit = kubev1.ResourceList{kubev1.ResourceCPU: userCPURequest}
}
rr = NewResourceRenderer(
nil,
userSpecifiedCPU,
userSpecifiedCPULimit,
userSpecifiedCPURequest,
WithCPUPinning(&v1.CPU{
Cores: 5,
IsolateEmulatorThread: true,
Expand All @@ -157,7 +163,10 @@ var _ = Describe("Resource pod spec renderer", func() {
kubev1.ResourceCPU,
addResources(userCPURequest, cpuIsolatedEmulatorThreadOverhead),
))
})
},
Entry("only CPU requests set by the user", false),
Entry("request and limits set by the user", true),
)
})
})

Expand Down
20 changes: 18 additions & 2 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import (
"kubevirt.io/kubevirt/tests/util"

v1 "kubevirt.io/api/core/v1"
virtv1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/client-go/log"

Expand Down Expand Up @@ -2370,14 +2371,17 @@ var _ = Describe("[sig-compute]Configurations", decorators.SigCompute, func() {
By("Checking if pod memory usage is > 80Mi")
Expect(m > 83886080).To(BeTrue(), "83886080 B = 80 Mi")
})
It("[test_id:4023]should start a vmi with dedicated cpus and isolated emulator thread", func() {
DescribeTable("[test_id:4023]should start a vmi with dedicated cpus and isolated emulator thread", func(resources *v1.ResourceRequirements) {

cpuVmi := libvmi.NewCirros()
cpuVmi.Spec.Domain.CPU = &v1.CPU{
Cores: 2,
DedicatedCPUPlacement: true,
IsolateEmulatorThread: true,
}
if resources != nil {
cpuVmi.Spec.Domain.Resources = *resources
}

By("Starting a VirtualMachineInstance")
cpuVmi, err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(cpuVmi)).Create(context.Background(), cpuVmi)
Expand Down Expand Up @@ -2445,7 +2449,19 @@ var _ = Describe("[sig-compute]Configurations", decorators.SigCompute, func() {
&expect.BSnd{S: "grep -c ^processor /proc/cpuinfo\n"},
&expect.BExp{R: "2"},
}, 15)).To(Succeed())
})
},
Entry("with explicit resources set", &virtv1.ResourceRequirements{
Requests: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("2"),
kubev1.ResourceMemory: resource.MustParse("256Mi"),
},
Limits: kubev1.ResourceList{
kubev1.ResourceCPU: resource.MustParse("2"),
kubev1.ResourceMemory: resource.MustParse("256Mi"),
},
}),
Entry("without resource requirements set", nil),
)

It("[test_id:4024]should fail the vmi creation if IsolateEmulatorThread requested without dedicated cpus", func() {
cpuVmi := libvmi.NewCirros()
Expand Down

0 comments on commit 3cc04f9

Please sign in to comment.