Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.26

require (
github.com/cert-manager/cert-manager v1.19.4
github.com/cobaltcore-dev/openstack-hypervisor-operator v0.0.0-20260309144200-9c8ed613a94c
github.com/cobaltcore-dev/openstack-hypervisor-operator v0.0.0-20260313120621-e3699e2ccab9
github.com/coreos/go-systemd/v22 v22.7.0
github.com/digitalocean/go-libvirt v0.0.0-20260217163227-273eaa321819
github.com/godbus/dbus/v5 v5.2.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cobaltcore-dev/openstack-hypervisor-operator v0.0.0-20260309144200-9c8ed613a94c h1:KylfcJikSMWNJnuNfG1Od6fNUw4kQTjseP7khmwVlrM=
github.com/cobaltcore-dev/openstack-hypervisor-operator v0.0.0-20260309144200-9c8ed613a94c/go.mod h1:b0KmJdxvRI8UXlGe8cRm5BD8Tm2WhF7zSKMSIRGyVL4=
github.com/cobaltcore-dev/openstack-hypervisor-operator v0.0.0-20260313120621-e3699e2ccab9 h1:fIQCfP6HTOMu9XqcRLUYeUCK2mPWcOkSqYVF9HUhQyE=
github.com/cobaltcore-dev/openstack-hypervisor-operator v0.0.0-20260313120621-e3699e2ccab9/go.mod h1:b0KmJdxvRI8UXlGe8cRm5BD8Tm2WhF7zSKMSIRGyVL4=
github.com/coreos/go-systemd/v22 v22.7.0 h1:LAEzFkke61DFROc7zNLX/WA2i5J8gYqe0rSj9KI28KA=
github.com/coreos/go-systemd/v22 v22.7.0/go.mod h1:xNUYtjHu2EDXbsxz1i41wouACIwT7Ybq9o0BQhMwD0w=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
Expand Down
69 changes: 53 additions & 16 deletions internal/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func (l *LibVirt) Process(hv v1.Hypervisor) (v1.Hypervisor, error) {
l.addCapabilities,
l.addDomainCapabilities,
l.addAllocationCapacity,
l.addEffectiveCapacity,
}
var err error
for _, processor := range processors {
Expand Down Expand Up @@ -458,14 +459,14 @@ func (l *LibVirt) addAllocationCapacity(old v1.Hypervisor) (v1.Hypervisor, error

cellsById[cell.ID] = v1.Cell{
CellID: cell.ID,
Allocation: map[string]resource.Quantity{
Allocation: map[v1.ResourceName]resource.Quantity{
// Will be updated below when we look at the domain infos.
"memory": *resource.NewQuantity(0, resource.BinarySI),
"cpu": *resource.NewQuantity(0, resource.DecimalSI),
v1.ResourceMemory: *resource.NewQuantity(0, resource.BinarySI),
v1.ResourceCPU: *resource.NewQuantity(0, resource.DecimalSI),
},
Capacity: map[string]resource.Quantity{
"memory": memoryCapacity,
"cpu": cpuCapacity,
Capacity: map[v1.ResourceName]resource.Quantity{
v1.ResourceMemory: memoryCapacity,
v1.ResourceCPU: cpuCapacity,
},
}
}
Expand Down Expand Up @@ -505,14 +506,14 @@ func (l *LibVirt) addAllocationCapacity(old v1.Hypervisor) (v1.Hypervisor, error
domInfo.Name, memoryNode.CellID,
)
}
memAllocCell := cell.Allocation["memory"]
memAllocCell := cell.Allocation[v1.ResourceMemory]
// If a domain is using multiple memory cells, assume the
// distribution across cells is even.
nCells := int64(len(domInfo.NumaTune.MemNodes)) // is non-zero
memAllocPerCell := *resource.
NewQuantity(memAlloc.Value()/nCells, resource.BinarySI)
memAllocCell.Add(memAllocPerCell)
cell.Allocation["memory"] = memAllocCell
cell.Allocation[v1.ResourceMemory] = memAllocCell
cellsById[memoryNode.CellID] = cell
}

Expand All @@ -528,14 +529,14 @@ func (l *LibVirt) addAllocationCapacity(old v1.Hypervisor) (v1.Hypervisor, error
domInfo.Name, cpuCell.ID,
)
}
cpuAllocCell := cell.Allocation["cpu"]
cpuAllocCell := cell.Allocation[v1.ResourceCPU]
// If a domain is using multiple cpu cells, assume the distribution
// across cells is even.
nCells := int64(len(domInfo.CPU.Numa.Cells)) // is non-zero
cpuAllocPerCell := *resource.
NewQuantity(cpuAlloc.Value()/nCells, resource.DecimalSI)
cpuAllocCell.Add(cpuAllocPerCell)
cell.Allocation["cpu"] = cpuAllocCell
cell.Allocation[v1.ResourceCPU] = cpuAllocCell
cellsById[cpuCell.ID] = cell
}
}
Expand All @@ -544,12 +545,48 @@ func (l *LibVirt) addAllocationCapacity(old v1.Hypervisor) (v1.Hypervisor, error
cellsAsSlice = append(cellsAsSlice, cell)
}

newHv.Status.Capacity = make(map[string]resource.Quantity)
newHv.Status.Capacity["memory"] = *totalMemoryCapacity
newHv.Status.Capacity["cpu"] = *totalCpuCapacity
newHv.Status.Allocation = make(map[string]resource.Quantity)
newHv.Status.Allocation["memory"] = *totalMemoryAlloc
newHv.Status.Allocation["cpu"] = *totalCpuAlloc
newHv.Status.Capacity = make(map[v1.ResourceName]resource.Quantity)
newHv.Status.Capacity[v1.ResourceMemory] = *totalMemoryCapacity
newHv.Status.Capacity[v1.ResourceCPU] = *totalCpuCapacity
newHv.Status.Allocation = make(map[v1.ResourceName]resource.Quantity)
newHv.Status.Allocation[v1.ResourceMemory] = *totalMemoryAlloc
newHv.Status.Allocation[v1.ResourceCPU] = *totalCpuAlloc
newHv.Status.Cells = cellsAsSlice
return newHv, nil
}

// Add the effective capacity to the hypervisor instance.
//
// The effective capacity is calculated as the physical capacity times the
// applied overcommit ratio, or 1.0 by default. In case the resulting values
// are fractional, they are floored.
func (l *LibVirt) addEffectiveCapacity(old v1.Hypervisor) (v1.Hypervisor, error) {
newHv := *old.DeepCopy()
// Always recreate the EffectiveCapacity map to remove stale entries
newHv.Status.EffectiveCapacity = make(map[v1.ResourceName]resource.Quantity)
for resourceName, capacity := range newHv.Status.Capacity {
overcommit, ok := newHv.Spec.Overcommit[resourceName]
if !ok {
overcommit = 1.0
}
flooredValue := int64(float64(capacity.Value()) * overcommit)
effectiveCapacity := resource.NewQuantity(flooredValue, capacity.Format)
newHv.Status.EffectiveCapacity[resourceName] = *effectiveCapacity
}
// Also apply this to each cell.
for i, cell := range newHv.Status.Cells {
// Always recreate the cell's EffectiveCapacity map to remove stale entries
cell.EffectiveCapacity = make(map[v1.ResourceName]resource.Quantity)
for resourceName, capacity := range cell.Capacity {
overcommit, ok := newHv.Spec.Overcommit[resourceName]
if !ok {
overcommit = 1.0
}
flooredValue := int64(float64(capacity.Value()) * overcommit)
effectiveCapacity := resource.NewQuantity(flooredValue, capacity.Format)
cell.EffectiveCapacity[resourceName] = *effectiveCapacity
}
newHv.Status.Cells[i] = cell
}
return newHv, nil
}
Loading
Loading