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
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,25 @@ func (r *HostOversubscriptionController) SetupWithManager(mgr ctrl.Manager, mcl
// the host is over-subscribed. Returns nil if capacity data is unavailable, empty map if no violation.
func computeViolations(allReservations []v1alpha1.Reservation, hv hv1.Hypervisor) map[hv1.ResourceName]resource.Quantity {
rep := capacity.NewHostUsageReport(hv, allReservations)
if rep.Oversubscribed == nil {
if rep.Total == nil {
return nil // no capacity data
}
// Only count types that represent real demand on this host's capacity.
// ReservationTypeFailoverHost is excluded: it blocks Spec.Resources = full host capacity
// for evacuation and is policed by a dedicated filter — counting it here would make every
// host with running VMs appear oversubscribed.
reserved := rep.ReservedTotal(
v1alpha1.ReservationTypeCommittedResource,
v1alpha1.ReservationTypeFailover,
v1alpha1.ReservationTypeInFlight,
)
violations := make(map[hv1.ResourceName]resource.Quantity)
for rn, excess := range rep.Oversubscribed {
if excess.Sign() > 0 {
violations[rn] = excess
for rn, total := range rep.Total {
demand := rep.Used[rn].DeepCopy()
demand.Add(reserved[rn])
if demand.Cmp(total) > 0 {
demand.Sub(total)
violations[rn] = demand
}
}
return violations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ func TestComputeViolations(t *testing.T) {
Status: v1alpha1.ReservationStatus{Host: "host-1"},
}},
},
{
// Regression: after the pkg/capacity refactor (31b2fe82), FailoverHost reservations
// were counted at full Spec.Resources (= entire host) instead of zero.
// With VMs running: Available = Total − Used − Total = −Used → false oversubscription.
name: "failover host reservation with running VMs does not cause false oversubscription",
hv: hv1.Hypervisor{
ObjectMeta: metav1.ObjectMeta{Name: "host-1"},
Status: hv1.HypervisorStatus{
EffectiveCapacity: map[hv1.ResourceName]resource.Quantity{
hv1.ResourceMemory: testGiB(512),
},
Allocation: map[hv1.ResourceName]resource.Quantity{
hv1.ResourceMemory: testGiB(256),
},
},
},
slots: []v1alpha1.Reservation{{
Spec: v1alpha1.ReservationSpec{
Type: v1alpha1.ReservationTypeFailoverHost,
TargetHost: "host-1",
Resources: map[hv1.ResourceName]resource.Quantity{hv1.ResourceMemory: testGiB(512)},
},
Status: v1alpha1.ReservationStatus{Host: "host-1"},
}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading