Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion v1/providers/sfcompute/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *SFCClient) GetInstance(ctx context.Context, id v1.CloudProviderInstance

func (c *SFCClient) getZone(ctx context.Context, location string, includeUnavailable bool) (*sfcnodes.ZoneListResponseData, error) {
// Fetch the zones to ensure the location is valid
zones, err := c.getZones(ctx, includeUnavailable)
zones, _, err := c.getZones(ctx, includeUnavailable)
if err != nil {
return nil, errors.WrapAndTrace(err)
}
Expand Down
35 changes: 29 additions & 6 deletions v1/providers/sfcompute/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *SFCClient) GetInstanceTypes(ctx context.Context, args v1.GetInstanceTyp

// Fetch all available zones
includeUnavailable := false
zones, err := c.getZones(ctx, includeUnavailable)
zones, limitReached, err := c.getZones(ctx, includeUnavailable)
if err != nil {
return nil, err
}
Expand All @@ -64,6 +64,10 @@ func (c *SFCClient) GetInstanceTypes(ctx context.Context, args v1.GetInstanceTyp
return nil, err
}

if limitReached {
instanceType.IsAvailable = false
}

if !v1.IsSelectedByArgs(*instanceType, args) {
c.logger.Debug(ctx, "sfc: GetInstanceTypes instance type not selected by args",
v1.LogField("instanceType", instanceType.Type),
Expand Down Expand Up @@ -155,30 +159,49 @@ func makeInstanceTypeName(zone sfcnodes.ZoneListResponseData) string {
}

func (c *SFCClient) GetLocations(ctx context.Context, args v1.GetLocationsArgs) ([]v1.Location, error) {
zones, err := c.getZones(ctx, args.IncludeUnavailable)
zones, limitReached, err := c.getZones(ctx, args.IncludeUnavailable)
if err != nil {
return nil, err
}

locations := make([]v1.Location, 0, len(zones))
for _, zone := range zones {
location := zoneToLocation(zone)
if limitReached {
location.Available = false
}
locations = append(locations, location)
}

return locations, nil
}

func (c *SFCClient) getZones(ctx context.Context, includeUnavailable bool) ([]sfcnodes.ZoneListResponseData, error) {
func (c *SFCClient) getZones(ctx context.Context, includeUnavailable bool) ([]sfcnodes.ZoneListResponseData, bool, error) {
// Fetch the nodes to check the active node count
respNodes, err := c.client.Nodes.List(ctx, sfcnodes.NodeListParams{})
if err != nil {
return nil, false, err
}

activeNodeCount := 0
for _, node := range respNodes.Data {
status := sfcStatusToLifecycleStatus(fmt.Sprint(node.Status))
if status == v1.LifecycleStatusRunning || status == v1.LifecycleStatusPending {
activeNodeCount++
}
}

limitReached := activeNodeCount >= 50

// Fetch the zones from the API
resp, err := c.client.Zones.List(ctx)
if err != nil {
return nil, err
return nil, false, err
}

// If there are no zones, return an empty list
if resp == nil || len(resp.Data) == 0 {
return []sfcnodes.ZoneListResponseData{}, nil
return []sfcnodes.ZoneListResponseData{}, limitReached, nil
}

zones := make([]sfcnodes.ZoneListResponseData, 0, len(resp.Data))
Expand All @@ -197,7 +220,7 @@ func (c *SFCClient) getZones(ctx context.Context, includeUnavailable bool) ([]sf
zones = append(zones, zone)
}

return zones, nil
return zones, limitReached, nil
}

func zoneToLocation(zone sfcnodes.ZoneListResponseData) v1.Location {
Expand Down