-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where a node that becomes ready after 2
mins can be treated as unready. Deprecated LongNotStarted In cases where node n1 would: 1) Be created at t=0min 2) Ready condition is true at t=2.5min 3) Not ready taint is removed at t=3min the ready node is counted as unready Tested cases after fix: 1) Case described above 2) Nodes not starting even after 15mins still treated as unready 3) Nodes created long ago that suddenly become unready are counted as unready.
- Loading branch information
1 parent
5f2e54a
commit 47039e0
Showing
5 changed files
with
168 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
apiv1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "k8s.io/autoscaler/cluster-autoscaler/utils/test" | ||
) | ||
|
||
func TestGetReadiness(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
condition apiv1.NodeConditionType | ||
status apiv1.ConditionStatus | ||
taintKey string | ||
expectedResult bool | ||
excludeLong bool | ||
}{ | ||
{"ready", apiv1.NodeReady, apiv1.ConditionTrue, "", true, true}, | ||
{"unready and unready taint", apiv1.NodeReady, apiv1.ConditionFalse, apiv1.TaintNodeNotReady, false, false}, | ||
{"readiness unknown and unready taint", apiv1.NodeReady, apiv1.ConditionUnknown, apiv1.TaintNodeNotReady, false, false}, | ||
{"disk pressure and disk pressure taint", apiv1.NodeDiskPressure, apiv1.ConditionTrue, apiv1.TaintNodeDiskPressure, false, false}, | ||
{"network unavailable and network unavailable taint", apiv1.NodeNetworkUnavailable, apiv1.ConditionTrue, apiv1.TaintNodeNetworkUnavailable, false, false}, | ||
{"ready but unready taint", apiv1.NodeReady, apiv1.ConditionTrue, apiv1.TaintNodeNotReady, false, false}, | ||
{"no disk pressure but disk pressure taint", apiv1.NodeDiskPressure, apiv1.ConditionFalse, apiv1.TaintNodeDiskPressure, false, false}, | ||
{"network available but network unavailable taint", apiv1.NodeNetworkUnavailable, apiv1.ConditionFalse, apiv1.TaintNodeNetworkUnavailable, false, false}, | ||
} | ||
for _, tc := range testCases { | ||
createTestNode := func(timeSinceCreation time.Duration) *apiv1.Node { | ||
node := BuildTestNode("n1", 1000, 1000) | ||
node.CreationTimestamp.Time = time.Time{} | ||
testedTime := node.CreationTimestamp.Time.Add(timeSinceCreation) | ||
|
||
SetNodeCondition(node, tc.condition, tc.status, testedTime) | ||
if tc.condition != apiv1.NodeReady { | ||
SetNodeCondition(node, apiv1.NodeReady, apiv1.ConditionTrue, testedTime) | ||
} | ||
|
||
if tc.taintKey != "" { | ||
node.Spec.Taints = []apiv1.Taint{{ | ||
Key: tc.taintKey, | ||
Effect: apiv1.TaintEffectNoSchedule, | ||
TimeAdded: &metav1.Time{Time: testedTime}, | ||
}} | ||
} | ||
|
||
return node | ||
} | ||
t.Run("recent "+tc.desc, func(t *testing.T) { | ||
node := createTestNode(1 * time.Minute) | ||
isReady, _, err := GetReadinessState(node) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.expectedResult, isReady) | ||
}) | ||
t.Run("long "+tc.desc, func(t *testing.T) { | ||
if tc.excludeLong { | ||
return | ||
} | ||
node := createTestNode(30 * time.Minute) | ||
// No matter what are the node's conditions, stop considering it not started after long enough. | ||
isReady, _, err := GetReadinessState(node) | ||
assert.NoError(t, err) | ||
assert.False(t, isReady) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters