Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exoscale): enhance UX around SKS nodepools #7433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# VSCode project files
**/.vscode
*.code-workspace
__debug_bin*

# Emacs save files
*~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ func (ts *cloudProviderTestSuite) TestExoscaleCloudProvider_NodeGroupForNode_Ins
nil,
)

ts.p.manager.client.(*exoscaleClientMock).
On("ListSKSClusters", ts.p.manager.ctx, ts.p.manager.zone).
Return(
[]*egoscale.SKSCluster{{
ID: &testSKSClusterID,
Name: &testSKSClusterName,
Nodepools: []*egoscale.SKSNodepool{{
ID: &testSKSNodepoolID,
InstancePoolID: &testInstancePoolID,
Name: &testSKSNodepoolName,
}},
}},
nil,
)

nodeGroup, err := ts.p.NodeGroupForNode(&apiv1.Node{
Spec: apiv1.NodeSpec{
ProviderID: toProviderID(testInstanceID),
Expand Down Expand Up @@ -280,7 +295,7 @@ func (ts *cloudProviderTestSuite) TestExoscaleCloudProvider_NodeGroupForNode_SKS
})
ts.Require().NoError(err)
ts.Require().NotNil(nodeGroup)
ts.Require().Equal(testInstancePoolID, nodeGroup.Id())
ts.Require().Equal(testSKSNodepoolID, nodeGroup.Id())
ts.Require().IsType(&sksNodepoolNodeGroup{}, nodeGroup)
}

Expand Down Expand Up @@ -359,6 +374,21 @@ func (ts *cloudProviderTestSuite) TestExoscaleCloudProvider_NodeGroups() {
nil,
)

ts.p.manager.client.(*exoscaleClientMock).
On("ListSKSClusters", ts.p.manager.ctx, ts.p.manager.zone).
Return(
[]*egoscale.SKSCluster{{
ID: &testSKSClusterID,
Name: &testSKSClusterName,
Nodepools: []*egoscale.SKSNodepool{{
ID: &testSKSNodepoolID,
InstancePoolID: &sksNodepoolInstancePoolID,
Name: &testSKSNodepoolName,
}},
}},
nil,
)

instancePoolNodeGroup, err := ts.p.NodeGroupForNode(&apiv1.Node{
Spec: apiv1.NodeSpec{
ProviderID: toProviderID(instancePoolInstanceID),
Expand Down Expand Up @@ -432,7 +462,11 @@ func (ts *cloudProviderTestSuite) TestExoscaleCloudProvider_NodeGroups() {

// ---------------------------------------------------------------

ts.Require().Len(ts.p.NodeGroups(), 2)
nodeGroups := ts.p.NodeGroups()
ts.Require().Len(nodeGroups, 2)
if len(nodeGroups) >= 2 {
ts.Require().Equal(nodeGroups[1].Id(), testSKSNodepoolID)
}
}

func TestSuiteExoscaleCloudProvider(t *testing.T) {
Expand Down
40 changes: 36 additions & 4 deletions cluster-autoscaler/cloudprovider/exoscale/exoscale_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,46 @@ func newManager(discoveryOpts cloudprovider.NodeGroupDiscoveryOptions) (*Manager
// based on the `--scan-interval`. By default it's 10 seconds.
func (m *Manager) Refresh() error {
var nodeGroups []cloudprovider.NodeGroup

// load clusters, it's required for SKS node groups check
sksClusters, err := m.client.ListSKSClusters(m.ctx, m.zone)
if err != nil {
errorf("unable to list SKS clusters: %v", err)
return err
}

for _, ng := range m.nodeGroups {
if _, err := m.client.GetInstancePool(m.ctx, m.zone, ng.Id()); err != nil {
if errors.Is(err, exoapi.ErrNotFound) {
// Check SKS Nodepool existence first
found := false
for _, c := range sksClusters {
for _, np := range c.Nodepools {
if *np.ID == ng.Id() {
if _, err := m.client.GetInstancePool(m.ctx, m.zone, *np.InstancePoolID); err != nil {
if !errors.Is(err, exoapi.ErrNotFound) {
errorf("unable to retrieve SKS Instance Pool %s: %v", ng.Id(), err)
return err
}
} else {
found = true
break
}
}
}
}

if !found {
// If SKS Nodepool is not found, check the Instance Pool
// it was the previous behavior which was less convenient for end user UX
if _, err := m.client.GetInstancePool(m.ctx, m.zone, ng.Id()); err != nil {
if !errors.Is(err, exoapi.ErrNotFound) {
errorf("unable to retrieve SKS Instance Pool %s: %v", ng.Id(), err)
return err
}

// Neither SKS Nodepool nor Instance Pool found, remove it from cache
debugf("removing node group %s from manager cache", ng.Id())
continue
}
errorf("unable to retrieve Instance Pool %s: %v", ng.Id(), err)
return err
}

nodeGroups = append(nodeGroups, ng)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ func (n *instancePoolNodeGroup) GetOptions(_ config.NodeGroupAutoscalingOptions)

func (n *instancePoolNodeGroup) waitUntilRunning(ctx context.Context) error {
return pollCmd(ctx, func() (bool, error) {
instancePool, err := n.m.client.GetInstancePool(ctx, n.m.zone, n.Id())
instancePool, err := n.m.client.GetInstancePool(ctx, n.m.zone, *n.instancePool.ID)
if err != nil {
errorf("unable to retrieve Instance Pool %s: %s", n.Id(), err)
errorf("unable to retrieve Instance Pool %s: %s", *n.instancePool.ID, err)
return false, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (n *sksNodepoolNodeGroup) DecreaseTargetSize(_ int) error {

// Id returns an unique identifier of the node group.
func (n *sksNodepoolNodeGroup) Id() string {
return *n.sksNodepool.InstancePoolID
return *n.sksNodepool.ID
}

// Debug returns a string containing all information regarding this node group.
Expand Down Expand Up @@ -229,9 +229,9 @@ func (n *sksNodepoolNodeGroup) GetOptions(_ config.NodeGroupAutoscalingOptions)

func (n *sksNodepoolNodeGroup) waitUntilRunning(ctx context.Context) error {
return pollCmd(ctx, func() (bool, error) {
instancePool, err := n.m.client.GetInstancePool(ctx, n.m.zone, n.Id())
instancePool, err := n.m.client.GetInstancePool(ctx, n.m.zone, *n.sksNodepool.InstancePoolID)
if err != nil {
errorf("unable to retrieve Instance Pool %s: %s", n.Id(), err)
errorf("unable to retrieve Instance Pool %s: %s", *n.sksNodepool.InstancePoolID, err)
return false, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (ts *cloudProviderTestSuite) TestSKSNodepoolNodeGroup_Id() {
maxSize: int(testComputeInstanceQuotaLimit),
}

ts.Require().Equal(testInstancePoolID, nodeGroup.Id())
ts.Require().Equal(testSKSNodepoolID, nodeGroup.Id())
}

func (ts *cloudProviderTestSuite) TestSKSNodepoolNodeGroup_Nodes() {
Expand Down
Loading