Skip to content

Commit

Permalink
Merge pull request #6628 from MaxFedotov/issues/6549
Browse files Browse the repository at this point in the history
[clusterapi] Do not skip nodegroups with minSize=maxSize
  • Loading branch information
k8s-ci-robot authored Mar 19, 2024
2 parents ce32577 + 6c65baa commit c16e0cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,8 @@ func TestControllerNodeGroupForNodeWithPositiveScalingBounds(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// We don't scale from 0 so nodes must belong to a
// nodegroup that has a scale size of at least 1.
if ng != nil {
// We allow scaling if minSize=maxSize
if ng == nil {
t.Fatalf("unexpected nodegroup: %v", ng)
}
}
Expand Down Expand Up @@ -1124,19 +1123,19 @@ func TestControllerNodeGroups(t *testing.T) {
nodeGroupMaxSizeAnnotationKey: "1",
}

// Test #5: machineset with no scaling bounds results in no nodegroups
// Test #5: 5 machineset with minSize=maxSize results in a five nodegroup
machineSetConfigs = createMachineSetTestConfigs(namespace, clusterName, RandomString(6), 5, 1, annotations, nil)
if err := addTestConfigs(t, controller, machineSetConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
assertNodegroupLen(t, controller, 0)
assertNodegroupLen(t, controller, 5)

// Test #6: machinedeployment with no scaling bounds results in no nodegroups
// Test #6: add 2 machinedeployment with minSize=maxSize
machineDeploymentConfigs = createMachineDeploymentTestConfigs(namespace, clusterName, RandomString(6), 2, 1, annotations, nil)
if err := addTestConfigs(t, controller, machineDeploymentConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
assertNodegroupLen(t, controller, 0)
assertNodegroupLen(t, controller, 7)

annotations = map[string]string{
nodeGroupMinSizeAnnotationKey: "-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package clusterapi

import (
"fmt"
"k8s.io/klog/v2"
"math/rand"

"github.com/pkg/errors"
Expand Down Expand Up @@ -360,7 +361,12 @@ func newNodeGroupFromScalableResource(controller *machineController, unstructure
}

// Ensure the node group would have the capacity to scale
if scalableResource.MaxSize()-scalableResource.MinSize() < 1 {
// allow MinSize = 0
// allow MaxSize = MinSize
// don't allow MaxSize < MinSize
// don't allow MaxSize = MinSize = 0
if scalableResource.MaxSize()-scalableResource.MinSize() < 0 || scalableResource.MaxSize() == 0 {
klog.V(4).Infof("nodegroup %s has no scaling capacity, skipping", scalableResource.Name())
return nil, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ func TestNodeGroupNewNodeGroupConstructor(t *testing.T) {
nodeCount: 5,
errors: false,
expectNil: true,
}, {
description: "no error and expect notNil: min=max=2",
annotations: map[string]string{
nodeGroupMinSizeAnnotationKey: "2",
nodeGroupMaxSizeAnnotationKey: "2",
},
nodeCount: 1,
minSize: 2,
maxSize: 2,
replicas: 1,
errors: false,
expectNil: false,
}}

newNodeGroup := func(controller *machineController, testConfig *testConfig) (*nodegroup, error) {
Expand Down

0 comments on commit c16e0cd

Please sign in to comment.