-
Notifications
You must be signed in to change notification settings - Fork 5
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
Adding Resource Fields for api.Machine
#203
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package api | ||
|
||
import "k8s.io/apimachinery/pkg/api/resource" | ||
|
||
type ResourceName string | ||
|
||
const ( | ||
ResourceCPU ResourceName = "cpu" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls don't create own ResourceName or type. Ideally reuse core package: core "github.com/ironcore-dev/ironcore/api/core/v1alpha1" |
||
ResourceMemory ResourceName = "memory" | ||
ResourceSGX ResourceName = "sgx" | ||
ResourceHugepages ResourceName = "hugepages" | ||
) | ||
|
||
type ResourceList map[ResourceName]resource.Quantity | ||
|
||
type NUMAPreferences struct { | ||
CPUNodes []int `json:"cpuNodes,omitempty"` | ||
MemoryNodes []int `json:"memoryNodes,omitempty"` | ||
IoNodes []int `json:"ioNodes,omitempty"` | ||
} | ||
|
||
type NUMAPlacement struct { | ||
CPUNodes []int `json:"cpuNodes"` | ||
MemoryNodes []int `json:"memoryNodes"` | ||
IoNodes []int `json:"ioNodes"` | ||
} | ||
|
||
// get returns the resource with name if specified, otherwise it returns a nil quantity with default format | ||
func (rl *ResourceList) get(name ResourceName, defaultFormat resource.Format) *resource.Quantity { | ||
if val, ok := (*rl)[name]; ok { | ||
return &val | ||
} | ||
return &resource.Quantity{Format: defaultFormat} | ||
} | ||
|
||
// CPU is a shorthand for getting the quantity associated with ResourceCPU. | ||
func (rl *ResourceList) CPU() *resource.Quantity { | ||
return rl.get(ResourceCPU, resource.DecimalSI) | ||
} | ||
|
||
// Memory is a shorthand for getting the quantity associated with ResourceMemory. | ||
func (rl *ResourceList) Memory() *resource.Quantity { | ||
return rl.get(ResourceMemory, resource.BinarySI) | ||
} | ||
|
||
// SGX is a shorthand for getting the quantity associated with ResourceSGX. | ||
func (rl *ResourceList) SGX() *resource.Quantity { | ||
return rl.get(ResourceSGX, resource.BinarySI) | ||
} | ||
|
||
// HugepagesEnabled is a shorthand for checking if hugepage is enabled. | ||
func (rl *ResourceList) HugepagesEnabled() bool { | ||
return rl.get(ResourceHugepages, resource.DecimalSI).Value() == 1 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -755,7 +755,7 @@ func (r *MachineReconciler) setDomainMetadata(log logr.Logger, machine *api.Mach | |
func (r *MachineReconciler) setDomainResources(machine *api.Machine, domain *libvirtxml.Domain) error { | ||
// TODO: check if there is better or check possible while conversion to uint | ||
domain.Memory = &libvirtxml.DomainMemory{ | ||
Value: uint(machine.Spec.MemoryBytes), | ||
Value: uint(machine.Spec.Resources.Memory().Value()), | ||
Unit: "Byte", | ||
} | ||
|
||
|
@@ -765,7 +765,7 @@ func (r *MachineReconciler) setDomainResources(machine *api.Machine, domain *lib | |
} | ||
} | ||
|
||
cpu := uint(machine.Spec.CpuMillis / 1000) | ||
cpu := uint(machine.Spec.Resources.CPU().Value() / 1000) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this logic is wrong. 8.6 will be rounded down to 8 what doesn't make sense for me. I prefer do rounded up. @afritzler do we need support millis unit? Cannot we support just whole cores? 1, 2, 3, 4, 5, 6, 7, 8, ... |
||
domain.VCPU = &libvirtxml.DomainVCPU{ | ||
Value: cpu, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here maybe you will need to add ResourceList too