Skip to content

Commit 3255b01

Browse files
Tweak max unhealthy nodes to make max 99% + add more tests
1 parent 49eb5c7 commit 3255b01

File tree

4 files changed

+116
-4
lines changed

4 files changed

+116
-4
lines changed

docs/configuration/nodegroup.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,6 @@ This field is required.
298298

299299
The maximum percentage of unhealthy nodes in the test set from `health_check_newest_nodes_percent`. Beyond this threshold all scaling activity is paused and unhealthy nodes are flushed out.
300300

301+
> **Note:** The valid range for `max_unhealthy_nodes_percent` is `0%` to `99%`.
302+
301303
This is an optional field. If not set, it will default to `0%`.

pkg/controller/controller_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controller
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67
"time"
78

@@ -442,3 +443,112 @@ func TestTaintUnhealthyInstances(t *testing.T) {
442443
})
443444
}
444445
}
446+
447+
func TestIsNodegroupHealthy(t *testing.T) {
448+
c := &Controller{}
449+
now := time.Now()
450+
gracePeriod := 10 * time.Minute
451+
452+
buildNodes := func(total int, unhealthy int, creationTime time.Time) []*v1.Node {
453+
nodes := make([]*v1.Node, total)
454+
for i := 0; i < total; i++ {
455+
notReady := i < unhealthy
456+
nodes[i] = test.BuildTestNode(test.NodeOpts{
457+
Name: fmt.Sprintf("n%d", i+1),
458+
NotReady: notReady,
459+
Creation: creationTime,
460+
})
461+
}
462+
return nodes
463+
}
464+
465+
oldCreationTime := now.Add(-2 * gracePeriod)
466+
newCreationTime := now.Add(-gracePeriod / 2)
467+
468+
tests := []struct {
469+
name string
470+
state *NodeGroupState
471+
nodes []*v1.Node
472+
healthy bool
473+
}{
474+
{
475+
name: "0 nodes, healthy",
476+
state: &NodeGroupState{
477+
Opts: NodeGroupOptions{
478+
unhealthyNodeGracePeriodDuration: gracePeriod,
479+
HealthCheckNewestNodesPercent: 100,
480+
MaxUnhealthyNodesPercent: 50,
481+
},
482+
},
483+
nodes: buildNodes(0, 0, oldCreationTime),
484+
healthy: true,
485+
},
486+
{
487+
name: "0 nodes, max unhealthy 0%, healthy",
488+
state: &NodeGroupState{
489+
Opts: NodeGroupOptions{
490+
unhealthyNodeGracePeriodDuration: gracePeriod,
491+
HealthCheckNewestNodesPercent: 100,
492+
MaxUnhealthyNodesPercent: 0,
493+
},
494+
},
495+
nodes: buildNodes(0, 0, oldCreationTime),
496+
healthy: true,
497+
},
498+
{
499+
name: "4 nodes, all nodes too new, healthy",
500+
state: &NodeGroupState{
501+
Opts: NodeGroupOptions{
502+
unhealthyNodeGracePeriodDuration: gracePeriod,
503+
HealthCheckNewestNodesPercent: 100,
504+
MaxUnhealthyNodesPercent: 50,
505+
},
506+
},
507+
nodes: buildNodes(4, 4, newCreationTime),
508+
healthy: true,
509+
},
510+
{
511+
name: "4 nodes, all nodes old, unhealthy",
512+
state: &NodeGroupState{
513+
Opts: NodeGroupOptions{
514+
unhealthyNodeGracePeriodDuration: gracePeriod,
515+
HealthCheckNewestNodesPercent: 100,
516+
MaxUnhealthyNodesPercent: 50,
517+
},
518+
},
519+
nodes: buildNodes(4, 4, oldCreationTime),
520+
healthy: false,
521+
},
522+
{
523+
name: "4 nodes, all healthy, max unhealthy 0%, healthy",
524+
state: &NodeGroupState{
525+
Opts: NodeGroupOptions{
526+
unhealthyNodeGracePeriodDuration: gracePeriod,
527+
HealthCheckNewestNodesPercent: 100,
528+
MaxUnhealthyNodesPercent: 0,
529+
},
530+
},
531+
nodes: buildNodes(4, 0, oldCreationTime),
532+
healthy: true,
533+
},
534+
{
535+
name: "4 nodes, all unhealthy, max unhealthy 100%, healthy",
536+
state: &NodeGroupState{
537+
Opts: NodeGroupOptions{
538+
unhealthyNodeGracePeriodDuration: gracePeriod,
539+
HealthCheckNewestNodesPercent: 100,
540+
MaxUnhealthyNodesPercent: 99,
541+
},
542+
},
543+
nodes: buildNodes(4, 4, oldCreationTime),
544+
healthy: false,
545+
},
546+
}
547+
548+
for _, tt := range tests {
549+
t.Run(tt.name, func(t *testing.T) {
550+
got := c.isNodegroupHealthy(tt.state, tt.nodes)
551+
assert.Equal(t, tt.healthy, got)
552+
})
553+
}
554+
}

pkg/controller/node_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func ValidateNodeGroup(nodegroup NodeGroupOptions) []error {
151151
checkThat(nodegroup.HealthCheckNewestNodesPercent > 0, "health_check_newest_nodes_percent must be greater than 0")
152152
checkThat(nodegroup.HealthCheckNewestNodesPercent <= 100, "health_check_newest_nodes_percent must be less than or equal to 100")
153153
checkThat(nodegroup.MaxUnhealthyNodesPercent >= 0, "max_unhealthy_nodes_percent must be greater than or equal to 0")
154-
checkThat(nodegroup.MaxUnhealthyNodesPercent <= 100, "max_unhealthy_nodes_percent must be less than or equal to 100")
154+
checkThat(nodegroup.MaxUnhealthyNodesPercent < 100, "max_unhealthy_nodes_percent must be less than 100")
155155
}
156156

157157
return problems

pkg/controller/node_group_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ func TestValidateNodeGroup(t *testing.T) {
506506
ScaleUpCoolDownPeriod: "55m",
507507
UnhealthyNodeGracePeriod: "500h",
508508
HealthCheckNewestNodesPercent: 1,
509-
MaxUnhealthyNodesPercent: 100,
509+
MaxUnhealthyNodesPercent: 99,
510510
},
511511
},
512512
nil,
@@ -560,7 +560,7 @@ func TestValidateNodeGroup(t *testing.T) {
560560
MaxNodeAge: "bla",
561561
UnhealthyNodeGracePeriod: "bla",
562562
HealthCheckNewestNodesPercent: 101,
563-
MaxUnhealthyNodesPercent: 101,
563+
MaxUnhealthyNodesPercent: 100,
564564
},
565565
},
566566
[]string{
@@ -573,7 +573,7 @@ func TestValidateNodeGroup(t *testing.T) {
573573
"max_node_age failed to parse into a time.Duration. Set to '0' or '' to disable, or a positive Go duration to enable.",
574574
"unhealthy_node_grace_period failed to parse into a time.Duration. check your formatting.",
575575
"health_check_newest_nodes_percent must be less than or equal to 100",
576-
"max_unhealthy_nodes_percent must be less than or equal to 100",
576+
"max_unhealthy_nodes_percent must be less than 100",
577577
},
578578
},
579579
{

0 commit comments

Comments
 (0)