ironcore-dev / libvirt-provider

Libvirt provider implementation of the IronCore compute interface
https://ironcore-dev.github.io/libvirt-provider/
Apache License 2.0
5 stars 5 forks source link

Define resource fields for `api.Machine` #181

Open so-sahu opened 9 months ago

so-sahu commented 9 months ago

Summary

This issue captures the efforts to extend the API machine object and the corresponding reconciler changes. The proposals and changes can be discussed in this issue.

so-sahu commented 9 months ago
type ResourceName string

const (
    ResourceCPU      ResourceName = "cpu"
    ResourceMemory   ResourceName = "memory"
    ResourceSGX      ResourceName = "sgx"
    ResourceHugepages ResourceName = "hugepages"
)

type MachineSpec struct {
        ...
    Resources ResourceList
    NumaNodes []int
        CPUPins map[int]int
        ...
}

type ResourceList map[ResourceName]resource.Quantity

func (rl *ResourceList) Get(name ResourceName) resource.Quantity {
    if val, ok := (*rl)[name]; ok {
        return val
    }
    return resource.Quantity{}
}

func (rl *ResourceList) Set(name ResourceName, value resource.Quantity) {
    (*rl)[name] = value
}

func (rl *ResourceList) CPU() resource.Quantity {
    return rl.Get(ResourceCPU)
}

func (rl *ResourceList) Memory() resource.Quantity {
    return rl.Get(ResourceMemory)
}

func (rl *ResourceList) SGX() resource.Quantity {
    return rl.Get(ResourceSGX)
}

func (rl *ResourceList) EnableHugepages() bool{
    if rl.Get(ResourceHugepages).Value() == 1 {
        return true
    }
    return false
}

Changes made

  1. ResourceName and ResourceList Types

    • ResourceName defines string constants for different types of resources (cpu, memory, sgx, hugepages).
    • ResourceList is a map that associates ResourceName with resource.Quantity to manage resource quantities.
  2. MachineSpec Struct

    • The MachineSpec struct now includes a Resources field of type ResourceList to store resource allocations.
  3. ResourceList Methods

    • Get(name ResourceName) resource.Quantity: Retrieves the quantity of the specified resource.
    • Set(name ResourceName, value resource.Quantity): Sets the quantity of the specified resource.
    • CPU(), Memory(), SGX(): Convenience methods to retrieve specific resource quantities.
    • EnableHugepages(): Checks if hugepages are enabled.

Impact

lukas016 commented 9 months ago

Why do you need VCUAllocationRatio, BlockedHugepages and BlockedCPUs in machine spec? It is important for resource manager only for my point of view.

lukas016 commented 9 months ago

Do you need NumaDomain? Isn't it len(NumaNodes)?

lukas016 commented 9 months ago

network cards and storage can be resources too which ideally will manage by resource manager too. Could you think maybe how we can implement it too?

lukas016 commented 9 months ago

what do you think about use resource.Quantity type? https://github.com/ironcore-dev/ironcore/blob/main/api/core/v1alpha1/resource.go

afritzler commented 9 months ago

How about the following. In the spec I have the possibility to assign a NUMA topoligy like this. If it is empty it is ignored (in case NUMA pinning is disabled) or a Scheduler/Resource Manager ensures that it is correctly filled later.

type MachineSpec struct {
    // Existing fields...

    NUMAPreferences NUMAPreferences `json:"numaPreferences,omitempty"`
}

type NUMAPreferences struct {
    CPUNodes    []int `json:"cpuNodes,omitempty"`
    MemoryNodes []int `json:"memoryNodes,omitempty"`
    IoNodes     []int `json:"ioNodes,omitempty"`
}

And in the Status you can update the information once the placement has been fulfilled.

type MachineStatus struct {
    // Existing fields...

    NUMAPlacement NUMAPlacement `json:"numaPlacement,omitempty"`
}

type NUMAPlacement struct {
    CPUNodes    []int `json:"cpuNodes"`
    MemoryNodes []int `json:"memoryNodes"`
    IoNodes     []int `json:"ioNodes"`
}