diff --git a/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_manager.go b/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_manager.go index 1b2e9e3e2574..a316d0f74490 100644 --- a/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_manager.go +++ b/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_manager.go @@ -120,7 +120,7 @@ func NewManager(configFile io.Reader) (*OvhCloudManager, error) { return nil, fmt.Errorf("failed to create OpenStack provider: %w", err) } - client, err = sdk.NewDefaultClientWithToken(openStackProvider.Token) + client, err = sdk.NewDefaultClientWithToken(openStackProvider.AuthUrl, openStackProvider.Token) case ApplicationConsumerAuthenticationType: client, err = sdk.NewClient(cfg.ApplicationEndpoint, cfg.ApplicationKey, cfg.ApplicationSecret, cfg.ApplicationConsumerKey) default: @@ -151,7 +151,7 @@ func (m *OvhCloudManager) ReAuthenticate() error { return fmt.Errorf("failed to re-authenticate OpenStack token: %w", err) } - client, err := sdk.NewDefaultClientWithToken(m.OpenStackProvider.Token) + client, err := sdk.NewDefaultClientWithToken(m.OpenStackProvider.AuthUrl, m.OpenStackProvider.Token) if err != nil { return fmt.Errorf("failed to re-create client: %w", err) } diff --git a/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_node_group.go b/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_node_group.go index 189f36f93d78..b8b68da84b78 100644 --- a/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_node_group.go +++ b/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_node_group.go @@ -314,6 +314,11 @@ func (ng *NodeGroup) Autoprovisioned() bool { // GetOptions returns NodeGroupAutoscalingOptions that should be used for this particular // NodeGroup. Returning a nil will result in using default options. func (ng *NodeGroup) GetOptions(defaults config.NodeGroupAutoscalingOptions) (*config.NodeGroupAutoscalingOptions, error) { + // If node group autoscaling options nil, return defaults + if ng.Autoscaling == nil { + return nil, nil + } + // Forge autoscaling configuration from node pool cfg := &config.NodeGroupAutoscalingOptions{ ScaleDownUnneededTime: time.Duration(ng.Autoscaling.ScaleDownUnneededTimeSeconds) * time.Second, diff --git a/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_node_group_test.go b/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_node_group_test.go index 713593e94a69..56defe35509b 100644 --- a/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_node_group_test.go +++ b/cluster-autoscaler/cloudprovider/ovhcloud/ovh_cloud_node_group_test.go @@ -116,15 +116,16 @@ func newTestNodeGroup(t *testing.T, isGpu bool) cloudprovider.NodeGroup { DesiredNodes: 3, MinNodes: 1, MaxNodes: 5, + Autoscaling: &sdk.NodePoolAutoscaling{ + ScaleDownUtilizationThreshold: 3.2, + ScaleDownUnneededTimeSeconds: 10, + ScaleDownUnreadyTimeSeconds: 20, + }, }, CurrentSize: 3, } - ng.NodePool.Autoscaling.ScaleDownUtilizationThreshold = 3.2 - ng.NodePool.Autoscaling.ScaleDownUnneededTimeSeconds = 10 - ng.NodePool.Autoscaling.ScaleDownUnreadyTimeSeconds = 20 - return ng } diff --git a/cluster-autoscaler/cloudprovider/ovhcloud/sdk/nodepool.go b/cluster-autoscaler/cloudprovider/ovhcloud/sdk/nodepool.go index 7f1e19ff2a04..02e0b440c0fe 100644 --- a/cluster-autoscaler/cloudprovider/ovhcloud/sdk/nodepool.go +++ b/cluster-autoscaler/cloudprovider/ovhcloud/sdk/nodepool.go @@ -43,21 +43,24 @@ type NodePool struct { AvailableNodes uint32 `json:"availableNodes"` UpToDateNodes uint32 `json:"upToDateNodes"` - Autoscaling struct { - CpuMin float32 `json:"cpuMin"` - CpuMax float32 `json:"cpuMax"` + Autoscaling *NodePoolAutoscaling `json:"autoscaling,omitempty"` - MemoryMin float32 `json:"memoryMin"` - MemoryMax float32 `json:"memoryMax"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` +} - ScaleDownUtilizationThreshold float32 `json:"scaleDownUtilizationThreshold"` +// NodePoolAutoscaling defines the node group autoscaling options from OVHcloud API +type NodePoolAutoscaling struct { + CpuMin float32 `json:"cpuMin"` + CpuMax float32 `json:"cpuMax"` - ScaleDownUnneededTimeSeconds int32 `json:"scaleDownUnneededTimeSeconds"` - ScaleDownUnreadyTimeSeconds int32 `json:"scaleDownUnreadyTimeSeconds"` - } `json:"autoscaling"` + MemoryMin float32 `json:"memoryMin"` + MemoryMax float32 `json:"memoryMax"` - CreatedAt time.Time `json:"createdAt"` - UpdatedAt time.Time `json:"updatedAt"` + ScaleDownUtilizationThreshold float32 `json:"scaleDownUtilizationThreshold"` + + ScaleDownUnneededTimeSeconds int32 `json:"scaleDownUnneededTimeSeconds"` + ScaleDownUnreadyTimeSeconds int32 `json:"scaleDownUnreadyTimeSeconds"` } // ListNodePools allows to list all node pools available in a cluster @@ -140,7 +143,7 @@ type UpdateNodePoolOpts struct { MinNodes *uint32 `json:"minNodes,omitempty"` MaxNodes *uint32 `json:"maxNodes,omitempty"` - Autoscale *bool `json:"autoscale"` + Autoscale *bool `json:"autoscale,omitempty"` NodesToRemove []string `json:"nodesToRemove,omitempty"` } diff --git a/cluster-autoscaler/cloudprovider/ovhcloud/sdk/openstack.go b/cluster-autoscaler/cloudprovider/ovhcloud/sdk/openstack.go index 415885287c7e..816c5ac2a7c0 100644 --- a/cluster-autoscaler/cloudprovider/ovhcloud/sdk/openstack.go +++ b/cluster-autoscaler/cloudprovider/ovhcloud/sdk/openstack.go @@ -31,6 +31,7 @@ const DefaultExpirationTime = 23 * time.Hour type OpenStackProvider struct { provider *gophercloud.ProviderClient + AuthUrl string Token string tokenExpirationTime time.Time } @@ -51,6 +52,7 @@ func NewOpenStackProvider(authUrl string, username string, password string, doma return &OpenStackProvider{ provider: provider, + AuthUrl: authUrl, Token: provider.Token(), tokenExpirationTime: time.Now().Add(DefaultExpirationTime), }, nil diff --git a/cluster-autoscaler/cloudprovider/ovhcloud/sdk/ovh.go b/cluster-autoscaler/cloudprovider/ovhcloud/sdk/ovh.go index 4e465d225d11..cccc8d2a2384 100644 --- a/cluster-autoscaler/cloudprovider/ovhcloud/sdk/ovh.go +++ b/cluster-autoscaler/cloudprovider/ovhcloud/sdk/ovh.go @@ -26,6 +26,7 @@ import ( "io/ioutil" "net/http" "strconv" + "strings" "sync" "time" ) @@ -130,8 +131,15 @@ func NewDefaultClient() (*Client, error) { // NewDefaultClientWithToken will load all it's parameter from environment // or configuration files using an OpenStack keystone token -func NewDefaultClientWithToken(token string) (*Client, error) { - client, err := NewClient(OvhEU, "none", "none", "none") +func NewDefaultClientWithToken(authUrl, token string) (*Client, error) { + // Find endpoint given the keystone auth url + endpoint := OvhEU + if strings.Contains(authUrl, "ovh.us") { + endpoint = OvhUS + } + + // Create OVH api client + client, err := NewClient(endpoint, "none", "none", "none") if err != nil { return nil, err }