mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-12-15 16:09:39 -05:00
Let operator manage autoscaling of node groups
This commit is contained in:
parent
67d9be38d7
commit
e301f575df
18 changed files with 499 additions and 42 deletions
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package client
|
||||
|
||||
// AutoscalingCloudProvider returns the cloud-provider name as used by k8s cluster-autoscaler.
|
||||
func (c *Client) AutoscalingCloudProvider() string {
|
||||
return "gce"
|
||||
}
|
||||
|
|
@ -40,3 +40,12 @@ func uriNormalize(imageURI string) string {
|
|||
}
|
||||
return matches[1]
|
||||
}
|
||||
|
||||
// ensureURIPrefixed ensures that a compute API URI is prefixed with the optional URI prefix.
|
||||
func ensureURIPrefixed(uri string) string {
|
||||
matches := computeAPIBase.FindStringSubmatch(uri)
|
||||
if len(matches) == 2 {
|
||||
return uri
|
||||
}
|
||||
return "https://www.googleapis.com/compute/v1/" + uri
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/api/iterator"
|
||||
computepb "google.golang.org/genproto/googleapis/cloud/compute/v1"
|
||||
|
|
@ -87,12 +86,23 @@ func (c *Client) SetScalingGroupImage(ctx context.Context, scalingGroupID, image
|
|||
}
|
||||
|
||||
// GetScalingGroupName retrieves the name of a scaling group.
|
||||
func (c *Client) GetScalingGroupName(ctx context.Context, scalingGroupID string) (string, error) {
|
||||
// This keeps the casing of the original name, but Kubernetes requires the name to be lowercase,
|
||||
// so use strings.ToLower() on the result if using the name in a Kubernetes context.
|
||||
func (c *Client) GetScalingGroupName(scalingGroupID string) (string, error) {
|
||||
_, _, instanceGroupName, err := splitInstanceGroupID(scalingGroupID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("getting scaling group name: %w", err)
|
||||
}
|
||||
return strings.ToLower(instanceGroupName), nil
|
||||
return instanceGroupName, nil
|
||||
}
|
||||
|
||||
// GetScalingGroupName retrieves the name of a scaling group as needed by the cluster-autoscaler.
|
||||
func (c *Client) GetAutoscalingGroupName(scalingGroupID string) (string, error) {
|
||||
project, zone, instanceGroupName, err := splitInstanceGroupID(scalingGroupID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("getting autoscaling scaling group name: %w", err)
|
||||
}
|
||||
return ensureURIPrefixed(fmt.Sprintf("projects/%s/zones/%s/instanceGroups/%s", project, zone, instanceGroupName)), nil
|
||||
}
|
||||
|
||||
// ListScalingGroups retrieves a list of scaling groups for the cluster.
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ func TestGetScalingGroupName(t *testing.T) {
|
|||
require := require.New(t)
|
||||
|
||||
client := Client{}
|
||||
gotName, err := client.GetScalingGroupName(context.Background(), tc.scalingGroupID)
|
||||
gotName, err := client.GetScalingGroupName(tc.scalingGroupID)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue