Skip to content

Commit

Permalink
Merge pull request #4109 from Kafei59/feat/ovh-us
Browse files Browse the repository at this point in the history
feat(ovh): enable OVHcloud provider for US side
  • Loading branch information
k8s-ci-robot authored Jun 10, 2021
2 parents c70efcf + 3257372 commit 2201e9b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
27 changes: 15 additions & 12 deletions cluster-autoscaler/cloudprovider/ovhcloud/sdk/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}
Expand Down
2 changes: 2 additions & 0 deletions cluster-autoscaler/cloudprovider/ovhcloud/sdk/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const DefaultExpirationTime = 23 * time.Hour
type OpenStackProvider struct {
provider *gophercloud.ProviderClient

AuthUrl string
Token string
tokenExpirationTime time.Time
}
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions cluster-autoscaler/cloudprovider/ovhcloud/sdk/ovh.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io/ioutil"
"net/http"
"strconv"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 2201e9b

Please sign in to comment.