Skip to content

Commit

Permalink
Merge branch 'master' into switch-migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Sep 17, 2024
2 parents 9087887 + 11c9d46 commit d35c36e
Show file tree
Hide file tree
Showing 7 changed files with 596 additions and 100 deletions.
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
43 changes: 28 additions & 15 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,43 +436,56 @@ 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 && ec.Liveliness == metal.MachineLivelinessAlive:
// the free and allocatable machine counts consider the same aspects as the query for electing the machine candidate!
cap.Allocatable++
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{}
for _, pc := range pcs {
pc := pc

for _, cap := range pc.ServerCapacities {
cap := cap

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)
}
}

for _, cap := range pc.ServerCapacities {
cap.RemainingReservations = cap.Reservations - cap.UsedReservations
}

res = append(res, *pc)
}

Expand Down
Loading

0 comments on commit d35c36e

Please sign in to comment.