@@ -74,68 +74,53 @@ func UnknownSize() *Size {
7474
7575// Matches returns true if the given machine hardware is inside the min/max values of the
7676// constraint.
77- func (c * Constraint ) Matches (hw MachineHardware ) (ConstraintMatchingLog , bool ) {
78- logentryFmt := fmt .Sprintf ("%%d >= %d && %%d <= %d" , c .Min , c .Max )
79- cml := ConstraintMatchingLog {Constraint : * c , Log : fmt .Sprintf ("no constraint matching %q" , c .Type )}
77+ func (c * Constraint ) Matches (hw MachineHardware ) bool {
8078 res := false
8179 switch c .Type {
8280 case CoreConstraint :
8381 res = uint64 (hw .CPUCores ) >= c .Min && uint64 (hw .CPUCores ) <= c .Max
84- cml .Log = fmt .Sprintf (logentryFmt , hw .CPUCores , hw .CPUCores )
8582 case MemoryConstraint :
8683 res = hw .Memory >= c .Min && hw .Memory <= c .Max
87- cml .Log = fmt .Sprintf (logentryFmt , hw .Memory , hw .Memory )
8884 case StorageConstraint :
8985 res = hw .DiskCapacity () >= c .Min && hw .DiskCapacity () <= c .Max
90- cml .Log = fmt .Sprintf (logentryFmt , hw .DiskCapacity (), hw .DiskCapacity ())
9186 case GPUConstraint :
9287 for model , count := range hw .GPUModels () {
9388 idMatches , err := filepath .Match (c .Identifier , model )
9489 if err != nil {
95- cml .Log = fmt .Sprintf ("cannot match gpu model:%v" , err )
96- return cml , false
90+ return false
9791 }
9892 res = count >= c .Min && count <= c .Max && idMatches
9993 if res {
10094 break
10195 }
10296 }
10397
104- cml .Log = fmt .Sprintf ("existing gpus:%#v required gpus:%s count %d-%d" , hw .MetalGPUs , c .Identifier , c .Min , c .Max )
10598 }
106- cml .Match = res
107- return cml , res
99+ return res
108100}
109101
110102// FromHardware searches a Size for given hardware specs. It will search
111103// for a size where the constraints matches the given hardware.
112- func (sz Sizes ) FromHardware (hardware MachineHardware ) (* Size , [] * SizeMatchingLog , error ) {
104+ func (sz Sizes ) FromHardware (hardware MachineHardware ) (* Size , error ) {
113105 var found []Size
114- matchlog := make ([]* SizeMatchingLog , 0 )
115- var matchedlog * SizeMatchingLog
116106nextsize:
117107 for _ , s := range sz {
118- ml := & SizeMatchingLog {Name : s .ID , Match : false }
119- matchlog = append (matchlog , ml )
120108 for _ , c := range s .Constraints {
121- lg , match := c .Matches (hardware )
122- ml .Constraints = append (ml .Constraints , lg )
109+ match := c .Matches (hardware )
123110 if ! match {
124111 continue nextsize
125112 }
126113 }
127- ml .Match = true
128- matchedlog = ml
129114 found = append (found , s )
130115 }
131116
132117 if len (found ) == 0 {
133- return nil , matchlog , NotFound ("no size found for hardware (%s)" , hardware .ReadableSpec ())
118+ return nil , NotFound ("no size found for hardware (%s)" , hardware .ReadableSpec ())
134119 }
135120 if len (found ) > 1 {
136- return nil , matchlog , fmt .Errorf ("%d sizes found for hardware (%s)" , len (found ), hardware .ReadableSpec ())
121+ return nil , fmt .Errorf ("%d sizes found for hardware (%s)" , len (found ), hardware .ReadableSpec ())
137122 }
138- return & found [0 ], [] * SizeMatchingLog { matchedlog }, nil
123+ return & found [0 ], nil
139124}
140125
141126func (s * Size ) overlaps (so * Size ) bool {
@@ -293,19 +278,3 @@ func (rs *Reservations) Validate(partitions PartitionMap, projects map[string]*m
293278
294279 return nil
295280}
296-
297- // A ConstraintMatchingLog is used do return a log message to the caller
298- // beside the constraint itself.
299- type ConstraintMatchingLog struct {
300- Constraint Constraint
301- Match bool
302- Log string
303- }
304-
305- // A SizeMatchingLog returns information about a list of constraints.
306- type SizeMatchingLog struct {
307- Name string
308- Log string
309- Match bool
310- Constraints []ConstraintMatchingLog
311- }
0 commit comments