Skip to content

Commit

Permalink
constellation-node-operator: don't bail out on listing errors
Browse files Browse the repository at this point in the history
If the GCP project has scaling groups for which our checks can't be performed (which is the case for regional scaling groups, as they "don't exist" for the operator, if deployed in another region) . In that case, we should not bail out directly but go on with the next group. An error should only be thrown if there are no matching groups at all.
  • Loading branch information
msanft committed Dec 3, 2024
1 parent a1da8aa commit 39117d1
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func (c *Client) GetAutoscalingGroupName(scalingGroupID string) (string, error)
}

// ListScalingGroups retrieves a list of scaling groups for the cluster.
func (c *Client) ListScalingGroups(ctx context.Context, uid string) ([]cspapi.ScalingGroup, error) {
results := []cspapi.ScalingGroup{}
func (c *Client) ListScalingGroups(ctx context.Context, uid string) (results []cspapi.ScalingGroup, retErr error) {
iter := c.instanceGroupManagersAPI.AggregatedList(ctx, &computepb.AggregatedListInstanceGroupManagersRequest{
Project: c.projectID,
})
Expand All @@ -129,7 +128,7 @@ func (c *Client) ListScalingGroups(ctx context.Context, uid string) ([]cspapi.Sc
}
template, err := c.instanceTemplateAPI.Get(c.projectID, templateURI[len(templateURI)-1])
if err != nil {
return nil, fmt.Errorf("getting instance template: %w", err)
errors.Join(retErr, fmt.Errorf("getting instance template %q: %w", templateURI[len(templateURI)-1], err))
}
if template.Properties == nil || template.Properties.Labels == nil {
continue
Expand All @@ -140,14 +139,14 @@ func (c *Client) ListScalingGroups(ctx context.Context, uid string) ([]cspapi.Sc

groupID, err := c.canonicalInstanceGroupID(ctx, *grpManager.SelfLink)
if err != nil {
return nil, fmt.Errorf("normalizing instance group ID: %w", err)
errors.Join(retErr, fmt.Errorf("getting canonical instance group ID: %w", err))
}

role := updatev1alpha1.NodeRoleFromString(template.Properties.Labels["constellation-role"])

name, err := c.GetScalingGroupName(groupID)
if err != nil {
return nil, fmt.Errorf("getting scaling group name: %w", err)
errors.Join(retErr, fmt.Errorf("getting scaling group name: %w", err))
}

nodeGroupName := template.Properties.Labels["constellation-node-group"]
Expand All @@ -164,7 +163,7 @@ func (c *Client) ListScalingGroups(ctx context.Context, uid string) ([]cspapi.Sc

autoscalerGroupName, err := c.GetAutoscalingGroupName(groupID)
if err != nil {
return nil, fmt.Errorf("getting autoscaling group name: %w", err)
errors.Join(retErr, fmt.Errorf("getting autoscaling group name: %w", err))
}

results = append(results, cspapi.ScalingGroup{
Expand All @@ -176,6 +175,11 @@ func (c *Client) ListScalingGroups(ctx context.Context, uid string) ([]cspapi.Sc
})
}
}

if len(results) == 0 {
return nil, fmt.Errorf("no scaling groups found: %w", retErr)
}

return results, nil
}

Expand Down

0 comments on commit 39117d1

Please sign in to comment.