Skip to content

Commit

Permalink
Fail fast for impossible fsl (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Aug 26, 2021
1 parent 3c8a745 commit 2bda0d3
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,16 @@ func allocateMachine(logger *zap.SugaredLogger, ds *datastore.RethinkStore, ipam
return nil, err
}

// Allocation of a specific machine is requested, therefor size and partition are not given, fetch them
if allocationSpec.UUID != "" {
m, err := ds.FindMachineByID(allocationSpec.UUID)
if err != nil {
return nil, err
}
allocationSpec.SizeID = m.SizeID
allocationSpec.PartitionID = m.PartitionID
}

// Check if more machine would be allocated than project quota permits
if p.GetProject() != nil && p.GetProject().GetQuotas() != nil && p.GetProject().GetQuotas().GetMachine() != nil {
mq := p.GetProject().GetQuotas().GetMachine()
Expand All @@ -1017,6 +1027,24 @@ func allocateMachine(logger *zap.SugaredLogger, ds *datastore.RethinkStore, ipam
}
}

var fsl *metal.FilesystemLayout
if allocationSpec.FilesystemLayoutID == nil {
fsls, err := ds.ListFilesystemLayouts()
if err != nil {
return nil, err
}

fsl, err = fsls.From(allocationSpec.SizeID, allocationSpec.Image.ID)
if err != nil {
return nil, err
}
} else {
fsl, err = ds.FindFilesystemLayout(*allocationSpec.FilesystemLayoutID)
if err != nil {
return nil, err
}
}

var machineCandidate *metal.Machine
err = retry.Do(
func() error {
Expand All @@ -1036,8 +1064,6 @@ func allocateMachine(logger *zap.SugaredLogger, ds *datastore.RethinkStore, ipam
}
// as some fields in the allocation spec are optional, they will now be clearly defined by the machine candidate
allocationSpec.UUID = machineCandidate.ID
allocationSpec.PartitionID = machineCandidate.PartitionID
allocationSpec.SizeID = machineCandidate.SizeID

alloc := &metal.MachineAllocation{
Creator: allocationSpec.Creator,
Expand Down Expand Up @@ -1077,24 +1103,6 @@ func allocateMachine(logger *zap.SugaredLogger, ds *datastore.RethinkStore, ipam
return err
}

var fsl *metal.FilesystemLayout
if allocationSpec.FilesystemLayoutID == nil {
fsls, err := ds.ListFilesystemLayouts()
if err != nil {
return nil, rollbackOnError(err)
}

fsl, err = fsls.From(allocationSpec.SizeID, allocationSpec.Image.ID)
if err != nil {
return nil, rollbackOnError(err)
}
} else {
fsl, err = ds.FindFilesystemLayout(*allocationSpec.FilesystemLayoutID)
if err != nil {
return nil, rollbackOnError(err)
}
}

err = fsl.Matches(machineCandidate.Hardware)
if err != nil {
return nil, rollbackOnError(err)
Expand Down

0 comments on commit 2bda0d3

Please sign in to comment.