Skip to content

Commit d9543b2

Browse files
authored
Merge pull request #8466 from dsafdsa1/csr-scaleup-time
Add tests for NodeGroupScaleUpTime()
2 parents 79aea9b + 220d5fb commit d9543b2

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

cluster-autoscaler/clusterstate/clusterstate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ func (csr *ClusterStateRegistry) MaxNodeProvisionTime(nodeGroup cloudprovider.No
205205
}
206206

207207
// NodeGroupScaleUpTime returns the start time of the most recent scale-up request for the given node group.
208+
// NOTE: Don't remove. This is used by providers who import CA as a framework/library.
208209
func (csr *ClusterStateRegistry) NodeGroupScaleUpTime(nodeGroup cloudprovider.NodeGroup) (time.Time, error) {
209-
// NOTE: Don't remove. This is used by providers who import CA as a framework/library.
210+
if nodeGroup == nil {
211+
return time.Time{}, fmt.Errorf("failed to find scaleUpRequest for node group: unexpected node group passed")
212+
}
210213
scaleUpRequest, found := csr.scaleUpRequests[nodeGroup.Id()]
211214
if !found {
212215
return time.Time{}, fmt.Errorf("failed to find scaleUpRequest for node group: %s", nodeGroup.Id())

cluster-autoscaler/clusterstate/clusterstate_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,37 @@ func TestRegisterScaleDown(t *testing.T) {
555555
assert.Empty(t, clusterstate.GetScaleUpFailures())
556556
}
557557

558+
func TestNodeGroupScaleUpTime(t *testing.T) {
559+
provider := testprovider.NewTestCloudProviderBuilder().Build()
560+
assert.NotNil(t, provider)
561+
562+
fakeClient := &fake.Clientset{}
563+
fakeLogRecorder, _ := utils.NewStatusMapRecorder(fakeClient, "kube-system", kube_record.NewFakeRecorder(5), false, "my-cool-configmap")
564+
clusterstate := NewClusterStateRegistry(provider, ClusterStateRegistryConfig{
565+
MaxTotalUnreadyPercentage: 10,
566+
OkTotalUnreadyCount: 1,
567+
}, fakeLogRecorder, newBackoff(), nodegroupconfig.NewDefaultNodeGroupConfigProcessor(config.NodeGroupAutoscalingOptions{MaxNodeProvisionTime: 15 * time.Minute}), asyncnodegroups.NewDefaultAsyncNodeGroupStateChecker())
568+
569+
// nil node group
570+
_, err := clusterstate.NodeGroupScaleUpTime(nil)
571+
assert.ErrorContains(t, err, "failed to find scaleUpRequest for node group: unexpected node group passed")
572+
573+
// node group that's not being scaled up
574+
provider.AddNodeGroup("ng1", 1, 10, 1)
575+
ng := provider.GetNodeGroup("ng1")
576+
577+
_, err = clusterstate.NodeGroupScaleUpTime(ng)
578+
assert.ErrorContains(t, err, "failed to find scaleUpRequest for node group")
579+
580+
// node group currently being scaled up
581+
wantScaleUpTime := time.Now()
582+
clusterstate.RegisterScaleUp(ng, 1, wantScaleUpTime)
583+
584+
gotScaleUpTime, err := clusterstate.NodeGroupScaleUpTime(ng)
585+
assert.NoError(t, err)
586+
assert.Equal(t, wantScaleUpTime, gotScaleUpTime)
587+
}
588+
558589
func TestUpcomingNodes(t *testing.T) {
559590
provider := testprovider.NewTestCloudProviderBuilder().Build()
560591
now := time.Now()

0 commit comments

Comments
 (0)