Skip to content
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

Take amount of reservations into account for free machine count. #538

Merged
merged 20 commits into from
Sep 13, 2024
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
12 changes: 0 additions & 12 deletions cmd/metal-api/internal/issues/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ func AllIssueTypes() []Type {
}
}

func NotAllocatableIssueTypes() []Type {
return []Type{
TypeNoPartition,
TypeLivelinessDead,
TypeLivelinessUnknown,
TypeLivelinessNotAvailable,
TypeFailedMachineReclaim,
TypeCrashLoop,
TypeNoEventContainer,
}
}

func NewIssueFromType(t Type) (issue, error) {
switch t {
case TypeNoPartition:
Expand Down
36 changes: 23 additions & 13 deletions cmd/metal-api/internal/service/partition-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (r *partitionResource) calcPartitionCapacity(pcr *v1.PartitionCapacityReque
machinesWithIssues, err := issues.Find(&issues.Config{
Machines: ms,
EventContainers: ecs,
Only: issues.NotAllocatableIssueTypes(),
Omit: []issues.Type{issues.TypeLastEventError},
})
if err != nil {
return nil, fmt.Errorf("unable to calculate machine issues: %w", err)
Expand Down Expand Up @@ -436,24 +436,32 @@ func (r *partitionResource) calcPartitionCapacity(pcr *v1.PartitionCapacityReque

cap.Total++

if m.Allocation != nil {
cap.Allocated++
continue
}

if _, ok := machinesWithIssues[m.ID]; ok {
cap.Faulty++
cap.FaultyMachines = append(cap.FaultyMachines, m.ID)
continue
}

if m.State.Value == metal.AvailableState && metal.ProvisioningEventWaiting == pointer.FirstOrZero(ec.Events).Event {
// allocation dependent counts
switch {
case m.Allocation != nil:
cap.Allocated++
case m.Waiting && !m.PreAllocated && m.State.Value == metal.AvailableState:
// the free machine count considers the same aspects as the query for electing the machine candidate!
cap.Free++
continue
default:
cap.Unavailable++
}

cap.Other++
cap.OtherMachines = append(cap.OtherMachines, m.ID)
// provisioning state dependent counts
switch pointer.FirstOrZero(ec.Events).Event { //nolint:exhaustive
case metal.ProvisioningEventPhonedHome:
cap.PhonedHome++
case metal.ProvisioningEventWaiting:
cap.Waiting++
default:
cap.Other++
cap.OtherMachines = append(cap.OtherMachines, m.ID)
}
}

res := []v1.PartitionCapacity{}
Expand All @@ -466,10 +474,12 @@ func (r *partitionResource) calcPartitionCapacity(pcr *v1.PartitionCapacityReque
size := sizesByID[cap.Size]

for _, reservation := range size.Reservations.ForPartition(pc.ID) {
reservation := reservation
usedReservations := min(len(machinesByProject[reservation.ProjectID].WithSize(size.ID).WithPartition(pc.ID)), reservation.Amount)

cap.Reservations += reservation.Amount
cap.UsedReservations += min(len(machinesByProject[reservation.ProjectID].WithSize(size.ID).WithPartition(pc.ID)), reservation.Amount)
cap.UsedReservations += usedReservations
cap.Free -= reservation.Amount - usedReservations
cap.Free = max(cap.Free, 0)
}
}

Expand Down
Loading