Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions v1/providers/sfcompute/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ func (c *SFCClient) getZones(ctx context.Context, includeUnavailable bool) ([]sf

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

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

// hasCurrentCapacity returns true if any availability rectangle covers the
// current time and has quantity > 0.
func hasCurrentCapacity(capacity []sfcnodes.ZoneListResponseDataAvailableCapacity) bool {
now := time.Now().Unix()
for _, c := range capacity {
if c.StartTimestamp <= now && now < c.EndTimestamp && c.Quantity > 0 {
return true
}
}
return false
}

func zoneToLocation(zone sfcnodes.ZoneListResponseData) v1.Location {
return v1.Location{
Name: zone.Name,
Expand Down
Loading