Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/metal-stack/metal-api int…
Browse files Browse the repository at this point in the history
…o dualstack-support
  • Loading branch information
majst01 committed Sep 13, 2024
2 parents d408762 + 732b6ca commit 8f06d84
Show file tree
Hide file tree
Showing 7 changed files with 541 additions and 99 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
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 @@ -369,7 +369,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 @@ -427,24 +427,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 @@ -457,10 +465,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

0 comments on commit 8f06d84

Please sign in to comment.