Merge pull request #8466 from dsafdsa1/csr-scaleup-time
Add tests for NodeGroupScaleUpTime()
This commit is contained in:
commit
d9543b2fc2
|
|
@ -205,8 +205,11 @@ func (csr *ClusterStateRegistry) MaxNodeProvisionTime(nodeGroup cloudprovider.No
|
|||
}
|
||||
|
||||
// NodeGroupScaleUpTime returns the start time of the most recent scale-up request for the given node group.
|
||||
// NOTE: Don't remove. This is used by providers who import CA as a framework/library.
|
||||
func (csr *ClusterStateRegistry) NodeGroupScaleUpTime(nodeGroup cloudprovider.NodeGroup) (time.Time, error) {
|
||||
// NOTE: Don't remove. This is used by providers who import CA as a framework/library.
|
||||
if nodeGroup == nil {
|
||||
return time.Time{}, fmt.Errorf("failed to find scaleUpRequest for node group: unexpected node group passed")
|
||||
}
|
||||
scaleUpRequest, found := csr.scaleUpRequests[nodeGroup.Id()]
|
||||
if !found {
|
||||
return time.Time{}, fmt.Errorf("failed to find scaleUpRequest for node group: %s", nodeGroup.Id())
|
||||
|
|
|
|||
|
|
@ -555,6 +555,37 @@ func TestRegisterScaleDown(t *testing.T) {
|
|||
assert.Empty(t, clusterstate.GetScaleUpFailures())
|
||||
}
|
||||
|
||||
func TestNodeGroupScaleUpTime(t *testing.T) {
|
||||
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||
assert.NotNil(t, provider)
|
||||
|
||||
fakeClient := &fake.Clientset{}
|
||||
fakeLogRecorder, _ := utils.NewStatusMapRecorder(fakeClient, "kube-system", kube_record.NewFakeRecorder(5), false, "my-cool-configmap")
|
||||
clusterstate := NewClusterStateRegistry(provider, ClusterStateRegistryConfig{
|
||||
MaxTotalUnreadyPercentage: 10,
|
||||
OkTotalUnreadyCount: 1,
|
||||
}, fakeLogRecorder, newBackoff(), nodegroupconfig.NewDefaultNodeGroupConfigProcessor(config.NodeGroupAutoscalingOptions{MaxNodeProvisionTime: 15 * time.Minute}), asyncnodegroups.NewDefaultAsyncNodeGroupStateChecker())
|
||||
|
||||
// nil node group
|
||||
_, err := clusterstate.NodeGroupScaleUpTime(nil)
|
||||
assert.ErrorContains(t, err, "failed to find scaleUpRequest for node group: unexpected node group passed")
|
||||
|
||||
// node group that's not being scaled up
|
||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||
ng := provider.GetNodeGroup("ng1")
|
||||
|
||||
_, err = clusterstate.NodeGroupScaleUpTime(ng)
|
||||
assert.ErrorContains(t, err, "failed to find scaleUpRequest for node group")
|
||||
|
||||
// node group currently being scaled up
|
||||
wantScaleUpTime := time.Now()
|
||||
clusterstate.RegisterScaleUp(ng, 1, wantScaleUpTime)
|
||||
|
||||
gotScaleUpTime, err := clusterstate.NodeGroupScaleUpTime(ng)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, wantScaleUpTime, gotScaleUpTime)
|
||||
}
|
||||
|
||||
func TestUpcomingNodes(t *testing.T) {
|
||||
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||
now := time.Now()
|
||||
|
|
|
|||
Loading…
Reference in New Issue