Merge pull request #2426 from digitalocean/doks-fix-max-size-check
doks: fix max size check, support increase to max
This commit is contained in:
commit
6da7fdfd62
|
|
@ -79,7 +79,7 @@ func (n *NodeGroup) IncreaseSize(delta int) error {
|
|||
|
||||
targetSize := n.nodePool.Count + delta
|
||||
|
||||
if targetSize >= n.MaxSize() {
|
||||
if targetSize > n.MaxSize() {
|
||||
return fmt.Errorf("size increase is too large. current: %d desired: %d max: %d",
|
||||
n.nodePool.Count, targetSize, n.MaxSize())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,9 @@ func TestNodeGroup_IncreaseSize(t *testing.T) {
|
|||
numberOfNodes := 3
|
||||
client := &doClientMock{}
|
||||
ng := testNodeGroup(client, &godo.KubernetesNodePool{
|
||||
Count: numberOfNodes,
|
||||
Count: numberOfNodes,
|
||||
MinNodes: 1,
|
||||
MaxNodes: 10,
|
||||
})
|
||||
|
||||
delta := 2
|
||||
|
|
@ -75,6 +77,36 @@ func TestNodeGroup_IncreaseSize(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("successful increase to maximum", func(t *testing.T) {
|
||||
numberOfNodes := 2
|
||||
maxNodes := 3
|
||||
client := &doClientMock{}
|
||||
ng := testNodeGroup(client, &godo.KubernetesNodePool{
|
||||
Count: numberOfNodes,
|
||||
AutoScale: true,
|
||||
MinNodes: 1,
|
||||
MaxNodes: maxNodes,
|
||||
})
|
||||
|
||||
delta := 1
|
||||
newCount := numberOfNodes + delta
|
||||
client.On("UpdateNodePool",
|
||||
ctx,
|
||||
ng.clusterID,
|
||||
ng.id,
|
||||
&godo.KubernetesNodePoolUpdateRequest{
|
||||
Count: &newCount,
|
||||
},
|
||||
).Return(
|
||||
&godo.KubernetesNodePool{Count: newCount},
|
||||
&godo.Response{},
|
||||
nil,
|
||||
).Once()
|
||||
|
||||
err := ng.IncreaseSize(delta)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("negative increase", func(t *testing.T) {
|
||||
numberOfNodes := 3
|
||||
delta := -1
|
||||
|
|
@ -182,7 +214,9 @@ func TestNodeGroup_DecreaseTargetSize(t *testing.T) {
|
|||
numberOfNodes := 3
|
||||
client := &doClientMock{}
|
||||
ng := testNodeGroup(client, &godo.KubernetesNodePool{
|
||||
Count: numberOfNodes,
|
||||
Count: numberOfNodes,
|
||||
MinNodes: 1,
|
||||
MaxNodes: 5,
|
||||
})
|
||||
|
||||
exp := fmt.Errorf("size decrease is too small. current: %d desired: %d min: %d",
|
||||
|
|
@ -328,7 +362,11 @@ func TestNodeGroup_Nodes(t *testing.T) {
|
|||
func TestNodeGroup_Debug(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
client := &doClientMock{}
|
||||
ng := testNodeGroup(client, &godo.KubernetesNodePool{Count: 3})
|
||||
ng := testNodeGroup(client, &godo.KubernetesNodePool{
|
||||
Count: 3,
|
||||
MinNodes: 1,
|
||||
MaxNodes: 200,
|
||||
})
|
||||
|
||||
d := ng.Debug()
|
||||
exp := "cluster ID: 1 (min:1 max:200)"
|
||||
|
|
@ -355,13 +393,18 @@ func TestNodeGroup_Exist(t *testing.T) {
|
|||
}
|
||||
|
||||
func testNodeGroup(client nodeGroupClient, np *godo.KubernetesNodePool) *NodeGroup {
|
||||
var minNodes, maxNodes int
|
||||
if np != nil {
|
||||
minNodes = np.MinNodes
|
||||
maxNodes = np.MaxNodes
|
||||
}
|
||||
return &NodeGroup{
|
||||
id: "1",
|
||||
clusterID: "1",
|
||||
client: client,
|
||||
nodePool: np,
|
||||
minSize: 1,
|
||||
maxSize: 200,
|
||||
minSize: minNodes,
|
||||
maxSize: maxNodes,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue