Skip to content

Commit

Permalink
Merge pull request #808 from akutz/fix/default-cpu-mem-limits
Browse files Browse the repository at this point in the history
🐛 Set CPU/mem limit to -1 if reservation & no limit
  • Loading branch information
akutz authored Nov 25, 2024
2 parents 442d1ec + 74d8dbc commit 3de1130
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/providers/vsphere/virtualmachine/configspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ func CreateConfigSpec(
if !res.Limits.Cpu.IsZero() {
lim := CPUQuantityToMhz(vmClassSpec.Policies.Resources.Limits.Cpu, minFreq)
configSpec.CpuAllocation.Limit = &lim
} else {
configSpec.CpuAllocation.Limit = ptr.To[int64](-1)
}
} else if configSpec.CpuAllocation == nil {
// Default to best effort.
Expand Down Expand Up @@ -139,6 +141,8 @@ func CreateConfigSpec(
if !res.Limits.Memory.IsZero() {
lim := MemoryQuantityToMb(vmClassSpec.Policies.Resources.Limits.Memory)
configSpec.MemoryAllocation.Limit = &lim
} else {
configSpec.MemoryAllocation.Limit = ptr.To[int64](-1)
}
} else if configSpec.MemoryAllocation == nil {
// Default to best effort.
Expand Down
17 changes: 17 additions & 0 deletions pkg/providers/vsphere/virtualmachine/configspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ var _ = Describe("CreateConfigSpec", func() {
Expect(configSpec.MemoryAllocation.Reservation).To(HaveValue(BeEquivalentTo(0)))
})
})

Context("VM Class has request but no limits", func() {
BeforeEach(func() {
vmClassSpec.Policies.Resources.Limits = vmopv1.VirtualMachineResourceSpec{}
})

It("returns expected config spec", func() {
Expect(configSpec.CpuAllocation.Shares).ToNot(BeNil())
Expect(configSpec.CpuAllocation.Shares.Level).To(Equal(vimtypes.SharesLevelNormal))
Expect(configSpec.CpuAllocation.Limit).To(HaveValue(BeEquivalentTo(-1)))
Expect(configSpec.CpuAllocation.Reservation).To(HaveValue(BeEquivalentTo(2684354560000)))
Expect(configSpec.MemoryAllocation.Shares).ToNot(BeNil())
Expect(configSpec.MemoryAllocation.Shares.Level).To(Equal(vimtypes.SharesLevelNormal))
Expect(configSpec.MemoryAllocation.Limit).To(HaveValue(BeEquivalentTo(-1)))
Expect(configSpec.MemoryAllocation.Reservation).To(HaveValue(BeEquivalentTo(2048)))
})
})
})

When("VM has no bios or instance uuid", func() {
Expand Down

0 comments on commit 3de1130

Please sign in to comment.