Skip to content

Commit

Permalink
Merge pull request #3242 from nilo19/bug/disable-increase-when-initia…
Browse files Browse the repository at this point in the history
…lizing

Disable increaseSize when the node group is under initialilzation.
  • Loading branch information
k8s-ci-robot authored Jun 25, 2020
2 parents 67dce2e + 81cb1a7 commit 1434d14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func NewAgentPool(spec *dynamic.NodeGroupSpec, az *AzureManager) (*AgentPool, er
minSize: spec.MinSize,
maxSize: spec.MaxSize,
manager: az,
curSize: -1,
}

if err := as.initialize(); err != nil {
Expand Down Expand Up @@ -302,6 +303,10 @@ func (as *AgentPool) IncreaseSize(delta int) error {
as.mutex.Lock()
defer as.mutex.Unlock()

if as.curSize == -1 {
return fmt.Errorf("the availability set %s is under initialization, skipping IncreaseSize", as.Name)
}

if delta <= 0 {
return fmt.Errorf("size increase must be positive")
}
Expand Down
4 changes: 4 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ func (scaleSet *ScaleSet) IncreaseSize(delta int) error {
return err
}

if size == -1 {
return fmt.Errorf("the scale set %s is under initialization, skipping IncreaseSize", scaleSet.Name)
}

if int(size)+delta > scaleSet.MaxSize() {
return fmt.Errorf("size increase too large - desired:%d max:%d", int(size)+delta, scaleSet.MaxSize())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"net/http"
"testing"
"time"

apiv1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
Expand Down Expand Up @@ -130,6 +131,13 @@ func TestIncreaseSize(t *testing.T) {
mockVMSSVMClient.EXPECT().List(gomock.Any(), provider.azureManager.config.ResourceGroup, "test-asg", gomock.Any()).Return(expectedVMSSVMs, nil).AnyTimes()
provider.azureManager.azClient.virtualMachineScaleSetVMsClient = mockVMSSVMClient

ss := newTestScaleSet(provider.azureManager, "test-asg")
ss.lastSizeRefresh = time.Now()
ss.curSize = -1
err := ss.IncreaseSize(100)
expectedErr := fmt.Errorf("the scale set test-asg is under initialization, skipping IncreaseSize")
assert.Equal(t, expectedErr, err)

registered := provider.azureManager.RegisterAsg(
newTestScaleSet(provider.azureManager, "test-asg"))
assert.True(t, registered)
Expand Down

0 comments on commit 1434d14

Please sign in to comment.