Skip to content

Commit 6739181

Browse files
authored
fixed instance type sync available for sf compute (#105)
1 parent 098cdd4 commit 6739181

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

v1/providers/sfcompute/instancetype.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ func (c *SFCClient) getZones(ctx context.Context, includeUnavailable bool) ([]sf
189189

190190
zones := make([]sfcnodes.ZoneListResponseData, 0, len(resp.Data))
191191
for _, zone := range resp.Data {
192-
// If the there is no available capacity, skip it
193-
if len(zone.AvailableCapacity) == 0 && !includeUnavailable {
192+
// If there is no current available capacity, skip it.
193+
// AvailableCapacity contains time-windowed rectangles; we must check
194+
// that at least one rectangle covers the current time with quantity > 0.
195+
if !hasCurrentCapacity(zone.AvailableCapacity) && !includeUnavailable {
194196
continue
195197
}
196198

@@ -206,6 +208,18 @@ func (c *SFCClient) getZones(ctx context.Context, includeUnavailable bool) ([]sf
206208
return zones, nil
207209
}
208210

211+
// hasCurrentCapacity returns true if any availability rectangle covers the
212+
// current time and has quantity > 0.
213+
func hasCurrentCapacity(capacity []sfcnodes.ZoneListResponseDataAvailableCapacity) bool {
214+
now := time.Now().Unix()
215+
for _, c := range capacity {
216+
if c.StartTimestamp <= now && now < c.EndTimestamp && c.Quantity > 0 {
217+
return true
218+
}
219+
}
220+
return false
221+
}
222+
209223
func zoneToLocation(zone sfcnodes.ZoneListResponseData) v1.Location {
210224
return v1.Location{
211225
Name: zone.Name,

0 commit comments

Comments
 (0)