Skip to content

Commit 68edad3

Browse files
committed
chore(vm): memory limits on Pod for namespaces with quotas
- Calculate discount quota from Pod limits. - Update 3p-kubevirt to fix regressions: 1) Set proper memory limits when namespace has quotas. 2) Add 60Mi extra to memory limits when cores fraction is specified. Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
1 parent e26b037 commit 68edad3

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

build/components/versions.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ firmware:
33
libvirt: v10.9.0
44
edk2: stable202411
55
core:
6-
3p-kubevirt: v1.6.2-v12n.27
6+
# Set tag after tagging 3p-kubevirt.
7+
3p-kubevirt: dvp/fix-memory-auto-limits-when-resource-quotas-present
78
3p-containerized-data-importer: v1.60.3-v12n.18
89
distribution: 2.8.3
910
package:

images/virt-artifact/werf.inc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ secrets:
1515
shell:
1616
install:
1717
- |
18+
# remove this line after tagging 3p-kubevirt.
19+
echo "Rebuild 3"
1820
echo "Git clone {{ $gitRepoName }} repository..."
1921
git clone --depth=1 $(cat /run/secrets/SOURCE_REPO)/{{ $gitRepoUrl }} --branch {{ $tag }} /src/kubevirt
2022

images/virtualization-artifact/pkg/controller/vm/internal/statistic.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ func (h *StatisticHandler) syncResources(changed *v1alpha2.VirtualMachine,
160160
}
161161

162162
memoryKVVMIRequest := kvvmi.Spec.Domain.Resources.Requests[corev1.ResourceMemory]
163-
memoryPodRequest := ctr.Resources.Requests[corev1.ResourceMemory]
163+
// Kubevirt makes memory limits equal or slightly greater than requests. See https://github.com/deckhouse/virtualization/pull/1947
164+
memoryPodLimit := ctr.Resources.Limits[corev1.ResourceMemory]
164165

165-
memoryOverhead := memoryPodRequest.DeepCopy()
166+
memoryOverhead := memoryPodLimit.DeepCopy()
166167
memoryOverhead.Sub(memoryKVVMIRequest)
167168
mi := int64(1024 * 1024)
168169
memoryOverhead = *resource.NewQuantity(int64(math.Ceil(float64(memoryOverhead.Value())/float64(mi)))*mi, resource.BinarySI)

images/virtualization-artifact/pkg/controller/vm/internal/statistic_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,40 @@ var _ = Describe("TestStatisticHandler", func() {
310310
MemoryRuntimeOverhead: 0,
311311
},
312312
),
313+
Entry("Memory overhead for Pod with equal limits and requests",
314+
newVM(1, ptr.To("25%"), "2Gi"),
315+
newKVVMIHotplug(1, 1, 16, "25", "2Gi", "256Gi"),
316+
newPod("250m", "1", "3Gi", "3Gi"),
317+
expectedValues{
318+
CPUCores: 1,
319+
CPUCoreFraction: "25%",
320+
CPURequestedCores: 250,
321+
CPURuntimeOverhead: 0,
322+
323+
TopologyCoresPerSocket: 1,
324+
TopologySockets: 1,
325+
326+
MemorySize: 2 * 1024 * 1024 * 1024,
327+
MemoryRuntimeOverhead: 1024 * 1024 * 1024,
328+
},
329+
),
330+
Entry("Memory overhead for Pod with limits greater than requests",
331+
newVM(1, ptr.To("25%"), "2Gi"),
332+
newKVVMIHotplug(1, 1, 16, "25", "2Gi", "256Gi"),
333+
newPod("250m", "1", "2Gi", "2108Mi"), // 2Gi+60Mi
334+
expectedValues{
335+
CPUCores: 1,
336+
CPUCoreFraction: "25%",
337+
CPURequestedCores: 250,
338+
CPURuntimeOverhead: 0,
339+
340+
TopologyCoresPerSocket: 1,
341+
TopologySockets: 1,
342+
343+
MemorySize: 2 * 1024 * 1024 * 1024,
344+
MemoryRuntimeOverhead: 60 * 1024 * 1024,
345+
},
346+
),
313347
)
314348
})
315349

0 commit comments

Comments
 (0)