From 993691b3043a0ca1fcb5970c94fe3a0f59c65aa3 Mon Sep 17 00:00:00 2001 From: Tyler Fong Date: Thu, 26 Mar 2026 12:08:23 -0700 Subject: [PATCH] fixed instance type sync available for sf compute --- v1/providers/sfcompute/instancetype.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/v1/providers/sfcompute/instancetype.go b/v1/providers/sfcompute/instancetype.go index bbaca04..34b7f3e 100644 --- a/v1/providers/sfcompute/instancetype.go +++ b/v1/providers/sfcompute/instancetype.go @@ -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 } @@ -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,