@@ -61,6 +61,10 @@ func countDisk(disk BlockDevice) (model string, count uint64) {
6161 return disk .Name , disk .Size
6262}
6363
64+ func countMemory (size uint64 ) (model string , count uint64 ) {
65+ return "" , size
66+ }
67+
6468// Sizes is a list of sizes.
6569type Sizes []Size
6670
@@ -114,9 +118,6 @@ func (c *Constraint) matches(hw MachineHardware) bool {
114118// With this we ensure that hardware matches exhaustive against the constraints.
115119func (hw * MachineHardware ) matches (constraints []Constraint , constraintType ConstraintType ) bool {
116120 filtered := lo .Filter (constraints , func (c Constraint , _ int ) bool { return c .Type == constraintType })
117- if len (filtered ) == 0 {
118- return true
119- }
120121
121122 switch constraintType {
122123 case StorageConstraint :
@@ -126,10 +127,9 @@ func (hw *MachineHardware) matches(constraints []Constraint, constraintType Cons
126127 case CoreConstraint :
127128 return exhaustiveMatch (filtered , hw .MetalCPUs , countCPU )
128129 case MemoryConstraint :
129- // Noop because we do not have different Memory types
130- return true
130+ return exhaustiveMatch (filtered , []uint64 {hw .Memory }, countMemory )
131131 default :
132- return true
132+ return false
133133 }
134134}
135135
@@ -168,15 +168,17 @@ nextsize:
168168}
169169
170170func (s * Size ) overlaps (so * Size ) bool {
171- if len (lo .FromPtr (so ).Constraints ) == 0 {
171+ if len (lo .FromPtr (so ).Constraints ) == 0 || len ( lo . FromPtr ( s ). Constraints ) == 0 {
172172 return false
173173 }
174+
174175 srcTypes := lo .GroupBy (s .Constraints , func (item Constraint ) ConstraintType {
175176 return item .Type
176177 })
177178 destTypes := lo .GroupBy (so .Constraints , func (item Constraint ) ConstraintType {
178179 return item .Type
179180 })
181+
180182 for t , srcConstraints := range srcTypes {
181183 constraints , ok := destTypes [t ]
182184 if ! ok {
@@ -191,6 +193,20 @@ func (s *Size) overlaps(so *Size) bool {
191193 }
192194 }
193195
196+ for t , destConstraints := range destTypes {
197+ constraints , ok := srcTypes [t ]
198+ if ! ok {
199+ return false
200+ }
201+ for _ , sc := range destConstraints {
202+ for _ , c := range constraints {
203+ if ! c .overlaps (sc ) {
204+ return false
205+ }
206+ }
207+ }
208+ }
209+
194210 return true
195211}
196212
0 commit comments