Merge pull request #8156 from BigDarkClown/master
Rewrite TestCloudProvider to use builder pattern
This commit is contained in:
commit
adf59d447b
|
|
@ -61,45 +61,84 @@ type TestCloudProvider struct {
|
||||||
resourceLimiter *cloudprovider.ResourceLimiter
|
resourceLimiter *cloudprovider.ResourceLimiter
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTestCloudProvider builds new TestCloudProvider
|
// TestCloudProviderBuilder is used to create CloudProvider
|
||||||
func NewTestCloudProvider(onScaleUp OnScaleUpFunc, onScaleDown OnScaleDownFunc) *TestCloudProvider {
|
type TestCloudProviderBuilder struct {
|
||||||
return &TestCloudProvider{
|
builders []func(p *TestCloudProvider)
|
||||||
nodes: make(map[string]string),
|
|
||||||
groups: make(map[string]cloudprovider.NodeGroup),
|
|
||||||
onScaleUp: onScaleUp,
|
|
||||||
onScaleDown: onScaleDown,
|
|
||||||
resourceLimiter: cloudprovider.NewResourceLimiter(make(map[string]int64), make(map[string]int64)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTestAutoprovisioningCloudProvider builds new TestCloudProvider with autoprovisioning support
|
// NewTestCloudProviderBuilder returns a new test cloud provider builder
|
||||||
func NewTestAutoprovisioningCloudProvider(onScaleUp OnScaleUpFunc, onScaleDown OnScaleDownFunc,
|
func NewTestCloudProviderBuilder() *TestCloudProviderBuilder {
|
||||||
onNodeGroupCreate OnNodeGroupCreateFunc, onNodeGroupDelete OnNodeGroupDeleteFunc,
|
return &TestCloudProviderBuilder{}
|
||||||
machineTypes []string, machineTemplates map[string]*framework.NodeInfo) *TestCloudProvider {
|
|
||||||
return &TestCloudProvider{
|
|
||||||
nodes: make(map[string]string),
|
|
||||||
groups: make(map[string]cloudprovider.NodeGroup),
|
|
||||||
onScaleUp: onScaleUp,
|
|
||||||
onScaleDown: onScaleDown,
|
|
||||||
onNodeGroupCreate: onNodeGroupCreate,
|
|
||||||
onNodeGroupDelete: onNodeGroupDelete,
|
|
||||||
machineTypes: machineTypes,
|
|
||||||
machineTemplates: machineTemplates,
|
|
||||||
resourceLimiter: cloudprovider.NewResourceLimiter(make(map[string]int64), make(map[string]int64)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTestNodeDeletionDetectionCloudProvider builds new TestCloudProvider with deletion detection support
|
// WithOnScaleUp adds scale-up handle function to provider
|
||||||
func NewTestNodeDeletionDetectionCloudProvider(onScaleUp OnScaleUpFunc, onScaleDown OnScaleDownFunc,
|
func (b *TestCloudProviderBuilder) WithOnScaleUp(onScaleUp OnScaleUpFunc) *TestCloudProviderBuilder {
|
||||||
hasInstance HasInstance) *TestCloudProvider {
|
b.builders = append(b.builders, func(p *TestCloudProvider) {
|
||||||
return &TestCloudProvider{
|
p.onScaleUp = onScaleUp
|
||||||
|
})
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithOnScaleDown adds scale-down handle function to provider
|
||||||
|
func (b *TestCloudProviderBuilder) WithOnScaleDown(onScaleDown OnScaleDownFunc) *TestCloudProviderBuilder {
|
||||||
|
b.builders = append(b.builders, func(p *TestCloudProvider) {
|
||||||
|
p.onScaleDown = onScaleDown
|
||||||
|
})
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithOnNodeGroupCreate adds node group creation handle function to provider
|
||||||
|
func (b *TestCloudProviderBuilder) WithOnNodeGroupCreate(onNodeGroupCreate OnNodeGroupCreateFunc) *TestCloudProviderBuilder {
|
||||||
|
b.builders = append(b.builders, func(p *TestCloudProvider) {
|
||||||
|
p.onNodeGroupCreate = onNodeGroupCreate
|
||||||
|
})
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithOnNodeGroupDelete adds node group deletion handle function to provider
|
||||||
|
func (b *TestCloudProviderBuilder) WithOnNodeGroupDelete(onNodeGroupDelete OnNodeGroupDeleteFunc) *TestCloudProviderBuilder {
|
||||||
|
b.builders = append(b.builders, func(p *TestCloudProvider) {
|
||||||
|
p.onNodeGroupDelete = onNodeGroupDelete
|
||||||
|
})
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMachineTypes adds machine types to provider
|
||||||
|
func (b *TestCloudProviderBuilder) WithMachineTypes(machineTypes []string) *TestCloudProviderBuilder {
|
||||||
|
b.builders = append(b.builders, func(p *TestCloudProvider) {
|
||||||
|
p.machineTypes = machineTypes
|
||||||
|
})
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMachineTemplates adds machine templates for provider
|
||||||
|
func (b *TestCloudProviderBuilder) WithMachineTemplates(machineTemplates map[string]*framework.NodeInfo) *TestCloudProviderBuilder {
|
||||||
|
b.builders = append(b.builders, func(p *TestCloudProvider) {
|
||||||
|
p.machineTemplates = machineTemplates
|
||||||
|
})
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithHasInstance adds has instance handler to provider
|
||||||
|
func (b *TestCloudProviderBuilder) WithHasInstance(hasInstance HasInstance) *TestCloudProviderBuilder {
|
||||||
|
b.builders = append(b.builders, func(p *TestCloudProvider) {
|
||||||
|
p.hasInstance = hasInstance
|
||||||
|
})
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build returns a built test cloud provider
|
||||||
|
func (b *TestCloudProviderBuilder) Build() *TestCloudProvider {
|
||||||
|
p := &TestCloudProvider{
|
||||||
nodes: make(map[string]string),
|
nodes: make(map[string]string),
|
||||||
groups: make(map[string]cloudprovider.NodeGroup),
|
groups: make(map[string]cloudprovider.NodeGroup),
|
||||||
onScaleUp: onScaleUp,
|
|
||||||
onScaleDown: onScaleDown,
|
|
||||||
hasInstance: hasInstance,
|
|
||||||
resourceLimiter: cloudprovider.NewResourceLimiter(make(map[string]int64), make(map[string]int64)),
|
resourceLimiter: cloudprovider.NewResourceLimiter(make(map[string]int64), make(map[string]int64)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, builder := range b.builders {
|
||||||
|
builder(p)
|
||||||
|
}
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns name of the cloud provider.
|
// Name returns name of the cloud provider.
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ func TestOKWithScaleUp(t *testing.T) {
|
||||||
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
||||||
SetNodeReadyState(ng2_1, true, now.Add(-time.Minute))
|
SetNodeReadyState(ng2_1, true, now.Add(-time.Minute))
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 5)
|
provider.AddNodeGroup("ng1", 1, 10, 5)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ func TestOKWithScaleUp(t *testing.T) {
|
||||||
func TestEmptyOK(t *testing.T) {
|
func TestEmptyOK(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 0, 10, 0)
|
provider.AddNodeGroup("ng1", 0, 10, 0)
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
||||||
|
|
@ -148,7 +148,7 @@ func TestHasNodeGroupStartedScaleUp(t *testing.T) {
|
||||||
for tn, tc := range tests {
|
for tn, tc := range tests {
|
||||||
t.Run(tn, func(t *testing.T) {
|
t.Run(tn, func(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 0, 5, tc.initialSize)
|
provider.AddNodeGroup("ng1", 0, 5, tc.initialSize)
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
fakeLogRecorder, _ := utils.NewStatusMapRecorder(fakeClient, "kube-system", kube_record.NewFakeRecorder(5), false, "my-cool-configmap")
|
fakeLogRecorder, _ := utils.NewStatusMapRecorder(fakeClient, "kube-system", kube_record.NewFakeRecorder(5), false, "my-cool-configmap")
|
||||||
|
|
@ -225,7 +225,7 @@ func TestRecalculateStateAfterNodeGroupSizeChanged(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup(ngName, 0, 1000, tc.newTarget)
|
provider.AddNodeGroup(ngName, 0, 1000, tc.newTarget)
|
||||||
|
|
||||||
fakeLogRecorder, _ := utils.NewStatusMapRecorder(&fake.Clientset{}, "kube-system", kube_record.NewFakeRecorder(5), false, "my-cool-configmap")
|
fakeLogRecorder, _ := utils.NewStatusMapRecorder(&fake.Clientset{}, "kube-system", kube_record.NewFakeRecorder(5), false, "my-cool-configmap")
|
||||||
|
|
@ -255,7 +255,7 @@ func TestOKOneUnreadyNode(t *testing.T) {
|
||||||
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
||||||
SetNodeReadyState(ng2_1, false, now.Add(-time.Minute))
|
SetNodeReadyState(ng2_1, false, now.Add(-time.Minute))
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
|
|
@ -294,7 +294,7 @@ func TestNodeWithoutNodeGroupDontCrash(t *testing.T) {
|
||||||
|
|
||||||
noNgNode := BuildTestNode("no_ng", 1000, 1000)
|
noNgNode := BuildTestNode("no_ng", 1000, 1000)
|
||||||
SetNodeReadyState(noNgNode, true, now.Add(-time.Minute))
|
SetNodeReadyState(noNgNode, true, now.Add(-time.Minute))
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNode("no_ng", noNgNode)
|
provider.AddNode("no_ng", noNgNode)
|
||||||
|
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
|
|
@ -317,7 +317,7 @@ func TestOKOneUnreadyNodeWithScaleDownCandidate(t *testing.T) {
|
||||||
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
||||||
SetNodeReadyState(ng2_1, false, now.Add(-time.Minute))
|
SetNodeReadyState(ng2_1, false, now.Add(-time.Minute))
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
|
|
@ -370,7 +370,7 @@ func TestMissingNodes(t *testing.T) {
|
||||||
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
||||||
SetNodeReadyState(ng2_1, true, now.Add(-time.Minute))
|
SetNodeReadyState(ng2_1, true, now.Add(-time.Minute))
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 5)
|
provider.AddNodeGroup("ng1", 1, 10, 5)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
|
|
||||||
|
|
@ -411,7 +411,7 @@ func TestTooManyUnready(t *testing.T) {
|
||||||
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
||||||
SetNodeReadyState(ng2_1, false, now.Add(-time.Minute))
|
SetNodeReadyState(ng2_1, false, now.Add(-time.Minute))
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
|
|
@ -440,7 +440,7 @@ func TestUnreadyLongAfterCreation(t *testing.T) {
|
||||||
SetNodeReadyState(ng2_1, false, now.Add(-time.Minute))
|
SetNodeReadyState(ng2_1, false, now.Add(-time.Minute))
|
||||||
ng2_1.CreationTimestamp = metav1.Time{Time: now.Add(-30 * time.Minute)}
|
ng2_1.CreationTimestamp = metav1.Time{Time: now.Add(-30 * time.Minute)}
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
|
|
@ -472,7 +472,7 @@ func TestNotStarted(t *testing.T) {
|
||||||
SetNodeNotReadyTaint(ng2_1)
|
SetNodeNotReadyTaint(ng2_1)
|
||||||
ng2_1.CreationTimestamp = metav1.Time{Time: now.Add(-10 * time.Minute)}
|
ng2_1.CreationTimestamp = metav1.Time{Time: now.Add(-10 * time.Minute)}
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
|
|
@ -511,7 +511,7 @@ func TestExpiredScaleUp(t *testing.T) {
|
||||||
ng1_1 := BuildTestNode("ng1-1", 1000, 1000)
|
ng1_1 := BuildTestNode("ng1-1", 1000, 1000)
|
||||||
SetNodeReadyState(ng1_1, true, now.Add(-time.Minute))
|
SetNodeReadyState(ng1_1, true, now.Add(-time.Minute))
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 5)
|
provider.AddNodeGroup("ng1", 1, 10, 5)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
@ -536,7 +536,7 @@ func TestExpiredScaleUp(t *testing.T) {
|
||||||
|
|
||||||
func TestRegisterScaleDown(t *testing.T) {
|
func TestRegisterScaleDown(t *testing.T) {
|
||||||
ng1_1 := BuildTestNode("ng1-1", 1000, 1000)
|
ng1_1 := BuildTestNode("ng1-1", 1000, 1000)
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
@ -556,7 +556,7 @@ func TestRegisterScaleDown(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpcomingNodes(t *testing.T) {
|
func TestUpcomingNodes(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
// 6 nodes are expected to come.
|
// 6 nodes are expected to come.
|
||||||
|
|
@ -629,8 +629,7 @@ func TestUpcomingNodes(t *testing.T) {
|
||||||
func TestTaintBasedNodeDeletion(t *testing.T) {
|
func TestTaintBasedNodeDeletion(t *testing.T) {
|
||||||
// Create a new Cloud Provider that does not implement the HasInstance check
|
// Create a new Cloud Provider that does not implement the HasInstance check
|
||||||
// it will return the ErrNotImplemented error instead.
|
// it will return the ErrNotImplemented error instead.
|
||||||
provider := testprovider.NewTestNodeDeletionDetectionCloudProvider(nil, nil,
|
provider := testprovider.NewTestCloudProviderBuilder().WithHasInstance(func(string) (bool, error) { return false, cloudprovider.ErrNotImplemented }).Build()
|
||||||
func(string) (bool, error) { return false, cloudprovider.ErrNotImplemented })
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
// One node is already there, for a second nde deletion / draining was already started.
|
// One node is already there, for a second nde deletion / draining was already started.
|
||||||
|
|
@ -667,7 +666,7 @@ func TestTaintBasedNodeDeletion(t *testing.T) {
|
||||||
|
|
||||||
func TestIncorrectSize(t *testing.T) {
|
func TestIncorrectSize(t *testing.T) {
|
||||||
ng1_1 := BuildTestNode("ng1-1", 1000, 1000)
|
ng1_1 := BuildTestNode("ng1-1", 1000, 1000)
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 5)
|
provider.AddNodeGroup("ng1", 1, 10, 5)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
@ -702,7 +701,7 @@ func TestUnregisteredNodes(t *testing.T) {
|
||||||
ng1_1.Spec.ProviderID = "ng1-1"
|
ng1_1.Spec.ProviderID = "ng1-1"
|
||||||
ng1_2 := BuildTestNode("ng1-2", 1000, 1000)
|
ng1_2 := BuildTestNode("ng1-2", 1000, 1000)
|
||||||
ng1_2.Spec.ProviderID = "ng1-2"
|
ng1_2.Spec.ProviderID = "ng1-2"
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 2)
|
provider.AddNodeGroup("ng1", 1, 10, 2)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
provider.AddNode("ng1", ng1_2)
|
provider.AddNode("ng1", ng1_2)
|
||||||
|
|
@ -750,7 +749,7 @@ func TestCloudProviderDeletedNodes(t *testing.T) {
|
||||||
SetNodeReadyState(noNgNode, true, now.Add(-time.Minute))
|
SetNodeReadyState(noNgNode, true, now.Add(-time.Minute))
|
||||||
|
|
||||||
noNgNode.Spec.ProviderID = "no-ng"
|
noNgNode.Spec.ProviderID = "no-ng"
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 2)
|
provider.AddNodeGroup("ng1", 1, 10, 2)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
provider.AddNode("ng1", ng1_2)
|
provider.AddNode("ng1", ng1_2)
|
||||||
|
|
@ -844,7 +843,7 @@ func TestScaleUpBackoff(t *testing.T) {
|
||||||
ng1_3 := BuildTestNode("ng1-3", 1000, 1000)
|
ng1_3 := BuildTestNode("ng1-3", 1000, 1000)
|
||||||
SetNodeReadyState(ng1_3, true, now.Add(-time.Minute))
|
SetNodeReadyState(ng1_3, true, now.Add(-time.Minute))
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 4)
|
provider.AddNodeGroup("ng1", 1, 10, 4)
|
||||||
ng1 := provider.GetNodeGroup("ng1")
|
ng1 := provider.GetNodeGroup("ng1")
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
|
|
@ -967,7 +966,7 @@ func TestGetClusterSize(t *testing.T) {
|
||||||
notAutoscaledNode := BuildTestNode("notAutoscaledNode", 1000, 1000)
|
notAutoscaledNode := BuildTestNode("notAutoscaledNode", 1000, 1000)
|
||||||
SetNodeReadyState(notAutoscaledNode, true, now.Add(-time.Minute))
|
SetNodeReadyState(notAutoscaledNode, true, now.Add(-time.Minute))
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 5)
|
provider.AddNodeGroup("ng1", 1, 10, 5)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
|
|
||||||
|
|
@ -1018,7 +1017,7 @@ func TestUpdateScaleUp(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
later := now.Add(time.Minute)
|
later := now.Add(time.Minute)
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 5)
|
provider.AddNodeGroup("ng1", 1, 10, 5)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 5)
|
provider.AddNodeGroup("ng2", 1, 10, 5)
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
|
|
@ -1065,7 +1064,7 @@ func TestUpdateScaleUp(t *testing.T) {
|
||||||
func TestScaleUpFailures(t *testing.T) {
|
func TestScaleUpFailures(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 0, 10, 0)
|
provider.AddNodeGroup("ng1", 0, 10, 0)
|
||||||
provider.AddNodeGroup("ng2", 0, 10, 0)
|
provider.AddNodeGroup("ng2", 0, 10, 0)
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
@ -1213,7 +1212,7 @@ func TestUpdateAcceptableRanges(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
for nodeGroupName, targetSize := range tc.targetSizes {
|
for nodeGroupName, targetSize := range tc.targetSizes {
|
||||||
provider.AddNodeGroup(nodeGroupName, 0, 1000, targetSize)
|
provider.AddNodeGroup(nodeGroupName, 0, 1000, targetSize)
|
||||||
}
|
}
|
||||||
|
|
@ -1397,7 +1396,7 @@ func TestUpdateIncorrectNodeGroupSizes(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
for nodeGroupName, acceptableRange := range tc.acceptableRanges {
|
for nodeGroupName, acceptableRange := range tc.acceptableRanges {
|
||||||
provider.AddNodeGroup(nodeGroupName, 0, 1000, acceptableRange.CurrentTarget)
|
provider.AddNodeGroup(nodeGroupName, 0, 1000, acceptableRange.CurrentTarget)
|
||||||
}
|
}
|
||||||
|
|
@ -1458,7 +1457,7 @@ func TestTruncateIfExceedMaxSize(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsNodeGroupRegistered(t *testing.T) {
|
func TestIsNodeGroupRegistered(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
registeredNodeGroupName := "registered-node-group"
|
registeredNodeGroupName := "registered-node-group"
|
||||||
provider.AddNodeGroup(registeredNodeGroupName, 1, 10, 1)
|
provider.AddNodeGroup(registeredNodeGroupName, 1, 10, 1)
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
|
|
@ -1537,7 +1536,7 @@ func TestUpcomingNodesFromUpcomingNodeGroups(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
for groupName, groupSize := range tc.nodeGroups {
|
for groupName, groupSize := range tc.nodeGroups {
|
||||||
provider.AddUpcomingNodeGroup(groupName, 1, 10, groupSize)
|
provider.AddUpcomingNodeGroup(groupName, 1, 10, groupSize)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ func TestCloudProviderNodeInstancesCache(t *testing.T) {
|
||||||
nodeNg4_1 := BuildTestNode("ng4-1", 1000, 1000)
|
nodeNg4_1 := BuildTestNode("ng4-1", 1000, 1000)
|
||||||
instanceNg4_1 := buildRunningInstance(nodeNg4_1.Name)
|
instanceNg4_1 := buildRunningInstance(nodeNg4_1.Name)
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng3", 1, 10, 1)
|
provider.AddNodeGroup("ng3", 1, 10, 1)
|
||||||
|
|
|
||||||
|
|
@ -1185,13 +1185,13 @@ func runStartDeletionTest(t *testing.T, tc startDeletionTestCase, force bool) {
|
||||||
|
|
||||||
// Hook node deletion at the level of cloud provider, to gather which nodes were deleted, and to fail the deletion for
|
// Hook node deletion at the level of cloud provider, to gather which nodes were deleted, and to fail the deletion for
|
||||||
// certain nodes to simulate errors.
|
// certain nodes to simulate errors.
|
||||||
provider := testprovider.NewTestCloudProvider(nil, func(nodeGroup string, node string) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleDown(func(nodeGroup string, node string) error {
|
||||||
if tc.failedNodeDeletion[node] {
|
if tc.failedNodeDeletion[node] {
|
||||||
return fmt.Errorf("SIMULATED ERROR: won't remove node")
|
return fmt.Errorf("SIMULATED ERROR: won't remove node")
|
||||||
}
|
}
|
||||||
deletedNodes <- node
|
deletedNodes <- node
|
||||||
return nil
|
return nil
|
||||||
})
|
}).Build()
|
||||||
for _, bucket := range emptyNodeGroupViews {
|
for _, bucket := range emptyNodeGroupViews {
|
||||||
bucket.Group.(*testprovider.TestNodeGroup).SetCloudProvider(provider)
|
bucket.Group.(*testprovider.TestNodeGroup).SetCloudProvider(provider)
|
||||||
provider.InsertNodeGroup(bucket.Group)
|
provider.InsertNodeGroup(bucket.Group)
|
||||||
|
|
@ -1497,13 +1497,13 @@ func TestStartDeletionInBatchBasic(t *testing.T) {
|
||||||
}
|
}
|
||||||
deletedResult := make(chan string)
|
deletedResult := make(chan string)
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
provider := testprovider.NewTestCloudProvider(nil, func(nodeGroupId string, node string) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleDown(func(nodeGroupId string, node string) error {
|
||||||
if gotFailedRequest(nodeGroupId) {
|
if gotFailedRequest(nodeGroupId) {
|
||||||
return fmt.Errorf("SIMULATED ERROR: won't remove node")
|
return fmt.Errorf("SIMULATED ERROR: won't remove node")
|
||||||
}
|
}
|
||||||
deletedResult <- nodeGroupId
|
deletedResult <- nodeGroupId
|
||||||
return nil
|
return nil
|
||||||
})
|
}).Build()
|
||||||
// 2d array represent the waves of pushing nodes to delete.
|
// 2d array represent the waves of pushing nodes to delete.
|
||||||
deleteNodes := [][]*apiv1.Node{}
|
deleteNodes := [][]*apiv1.Node{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddNodeToBucket(t *testing.T) {
|
func TestAddNodeToBucket(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
ctx, err := NewScaleTestAutoscalingContext(config.AutoscalingOptions{}, nil, nil, provider, nil, nil)
|
ctx, err := NewScaleTestAutoscalingContext(config.AutoscalingOptions{}, nil, nil, provider, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Couldn't set up autoscaling context: %v", err)
|
t.Fatalf("Couldn't set up autoscaling context: %v", err)
|
||||||
|
|
@ -142,14 +142,14 @@ func TestRemove(t *testing.T) {
|
||||||
notDeletedNodes := make(chan string, 10)
|
notDeletedNodes := make(chan string, 10)
|
||||||
// Hook node deletion at the level of cloud provider, to gather which nodes were deleted, and to fail the deletion for
|
// Hook node deletion at the level of cloud provider, to gather which nodes were deleted, and to fail the deletion for
|
||||||
// certain nodes to simulate errors.
|
// certain nodes to simulate errors.
|
||||||
provider := testprovider.NewTestCloudProvider(nil, func(nodeGroup string, node string) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleDown(func(nodeGroup string, node string) error {
|
||||||
if failedNodeDeletion[node] {
|
if failedNodeDeletion[node] {
|
||||||
notDeletedNodes <- node
|
notDeletedNodes <- node
|
||||||
return fmt.Errorf("SIMULATED ERROR: won't remove node")
|
return fmt.Errorf("SIMULATED ERROR: won't remove node")
|
||||||
}
|
}
|
||||||
deletedNodes <- node
|
deletedNodes <- node
|
||||||
return nil
|
return nil
|
||||||
})
|
}).Build()
|
||||||
|
|
||||||
fakeClient.Fake.AddReactor("update", "nodes",
|
fakeClient.Fake.AddReactor("update", "nodes",
|
||||||
func(action core.Action) (bool, runtime.Object, error) {
|
func(action core.Action) (bool, runtime.Object, error) {
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func TestDaemonSetEvictionForEmptyNodes(t *testing.T) {
|
||||||
deletedPods <- eviction.Name
|
deletedPods <- eviction.Name
|
||||||
return true, nil, nil
|
return true, nil, nil
|
||||||
})
|
})
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
registry := kube_util.NewListerRegistry(nil, nil, nil, nil, nil, nil, nil, nil, nil)
|
registry := kube_util.NewListerRegistry(nil, nil, nil, nil, nil, nil, nil, nil, nil)
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,9 @@ func TestScheduleDeletion(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, func(nodeGroup string, node string) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleDown(func(nodeGroup string, node string) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
}).Build()
|
||||||
|
|
||||||
batcher := &countingBatcher{}
|
batcher := &countingBatcher{}
|
||||||
tracker := deletiontracker.NewNodeDeletionTracker(0)
|
tracker := deletiontracker.NewNodeDeletionTracker(0)
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,10 @@ func TestSoftTaintUpdate(t *testing.T) {
|
||||||
_, err = fakeClient.CoreV1().Nodes().Create(ctx, n2000, metav1.CreateOptions{})
|
_, err = fakeClient.CoreV1().Nodes().Create(ctx, n2000, metav1.CreateOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, func(nodeGroup string, node string) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleDown(func(nodeGroup string, node string) error {
|
||||||
t.Fatalf("Unexpected deletion of %s", node)
|
t.Fatalf("Unexpected deletion of %s", node)
|
||||||
return nil
|
return nil
|
||||||
})
|
}).Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 2)
|
provider.AddNodeGroup("ng1", 1, 10, 2)
|
||||||
provider.AddNode("ng1", n1000)
|
provider.AddNode("ng1", n1000)
|
||||||
provider.AddNode("ng1", n2000)
|
provider.AddNode("ng1", n2000)
|
||||||
|
|
@ -141,7 +141,7 @@ func TestSoftTaintTimeLimit(t *testing.T) {
|
||||||
return false, nil, nil
|
return false, nil, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 2)
|
provider.AddNodeGroup("ng1", 1, 10, 2)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
provider.AddNode("ng1", n2)
|
provider.AddNode("ng1", n2)
|
||||||
|
|
|
||||||
|
|
@ -420,9 +420,9 @@ func TestCropNodesToBudgets(t *testing.T) {
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tn, func(t *testing.T) {
|
t.Run(tn, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, func(nodeGroup string, node string) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleDown(func(nodeGroup string, node string) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
}).Build()
|
||||||
for _, bucket := range append(tc.empty, tc.drain...) {
|
for _, bucket := range append(tc.empty, tc.drain...) {
|
||||||
bucket.Group.(*testprovider.TestNodeGroup).SetCloudProvider(provider)
|
bucket.Group.(*testprovider.TestNodeGroup).SetCloudProvider(provider)
|
||||||
provider.InsertNodeGroup(bucket.Group)
|
provider.InsertNodeGroup(bucket.Group)
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ func TestFilterOutUnremovable(t *testing.T) {
|
||||||
}
|
}
|
||||||
s := nodegroupconfig.NewDefaultNodeGroupConfigProcessor(options.NodeGroupDefaults)
|
s := nodegroupconfig.NewDefaultNodeGroupConfigProcessor(options.NodeGroupDefaults)
|
||||||
c := NewChecker(s)
|
c := NewChecker(s)
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 2)
|
provider.AddNodeGroup("ng1", 1, 10, 2)
|
||||||
for _, n := range tc.nodes {
|
for _, n := range tc.nodes {
|
||||||
provider.AddNode("ng1", n)
|
provider.AddNode("ng1", n)
|
||||||
|
|
|
||||||
|
|
@ -485,7 +485,7 @@ func TestUpdateClusterState(t *testing.T) {
|
||||||
rsLister, err := kube_util.NewTestReplicaSetLister(tc.replicasSets)
|
rsLister, err := kube_util.NewTestReplicaSetLister(tc.replicasSets)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
registry := kube_util.NewListerRegistry(nil, nil, nil, nil, nil, nil, nil, rsLister, nil)
|
registry := kube_util.NewListerRegistry(nil, nil, nil, nil, nil, nil, nil, rsLister, nil)
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 0, 0, 0)
|
provider.AddNodeGroup("ng1", 0, 0, 0)
|
||||||
for _, node := range tc.nodes {
|
for _, node := range tc.nodes {
|
||||||
provider.AddNode("ng1", node)
|
provider.AddNode("ng1", node)
|
||||||
|
|
@ -681,7 +681,7 @@ func TestUpdateClusterStatUnneededNodesLimit(t *testing.T) {
|
||||||
for i := 0; i < tc.previouslyUnneeded; i++ {
|
for i := 0; i < tc.previouslyUnneeded; i++ {
|
||||||
previouslyUnneeded[i] = simulator.NodeToBeRemoved{Node: nodes[i]}
|
previouslyUnneeded[i] = simulator.NodeToBeRemoved{Node: nodes[i]}
|
||||||
}
|
}
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroupWithCustomOptions("ng1", 0, 0, 0, tc.opts)
|
provider.AddNodeGroupWithCustomOptions("ng1", 0, 0, 0, tc.opts)
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
provider.AddNode("ng1", node)
|
provider.AddNode("ng1", node)
|
||||||
|
|
@ -844,7 +844,7 @@ func TestNodesToDelete(t *testing.T) {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
allNodes := []*apiv1.Node{}
|
allNodes := []*apiv1.Node{}
|
||||||
allRemovables := []simulator.NodeToBeRemoved{}
|
allRemovables := []simulator.NodeToBeRemoved{}
|
||||||
for ng, nodes := range tc.nodes {
|
for ng, nodes := range tc.nodes {
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ func TestRemovableAt(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
removableNodes := append(empty, drain...)
|
removableNodes := append(empty, drain...)
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.InsertNodeGroup(ng)
|
provider.InsertNodeGroup(ng)
|
||||||
for _, node := range removableNodes {
|
for _, node := range removableNodes {
|
||||||
provider.AddNode("ng", node.Node)
|
provider.AddNode("ng", node.Node)
|
||||||
|
|
|
||||||
|
|
@ -44,13 +44,12 @@ import (
|
||||||
func TestNodePoolAsyncInitialization(t *testing.T) {
|
func TestNodePoolAsyncInitialization(t *testing.T) {
|
||||||
scaleUpSize := 3
|
scaleUpSize := 3
|
||||||
failingNodeGroupName := "failing-ng"
|
failingNodeGroupName := "failing-ng"
|
||||||
provider := testprovider.NewTestCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodeGroup string, increase int) error {
|
||||||
func(nodeGroup string, increase int) error {
|
if nodeGroup == failingNodeGroupName {
|
||||||
if nodeGroup == failingNodeGroupName {
|
return fmt.Errorf("Simulated error")
|
||||||
return fmt.Errorf("Simulated error")
|
}
|
||||||
}
|
return nil
|
||||||
return nil
|
}).Build()
|
||||||
}, nil)
|
|
||||||
pod := BuildTestPod("p1", 2, 1000)
|
pod := BuildTestPod("p1", 2, 1000)
|
||||||
failingNodeGroup := provider.BuildNodeGroup(failingNodeGroupName, 0, 100, 0, false, true, "T1", nil)
|
failingNodeGroup := provider.BuildNodeGroup(failingNodeGroupName, 0, 100, 0, false, true, "T1", nil)
|
||||||
successfulNodeGroup := provider.BuildNodeGroup("async-ng", 0, 100, 0, false, true, "T1", nil)
|
successfulNodeGroup := provider.BuildNodeGroup("async-ng", 0, 100, 0, false, true, "T1", nil)
|
||||||
|
|
|
||||||
|
|
@ -1003,9 +1003,9 @@ func runSimpleScaleUpTest(t *testing.T, config *ScaleUpTestConfig) *ScaleUpTestR
|
||||||
machineTemplates[ntc.NodeGroupName] = ntc.NodeInfo
|
machineTemplates[ntc.NodeGroupName] = ntc.NodeInfo
|
||||||
machineTemplates[ntc.MachineType] = ntc.NodeInfo
|
machineTemplates[ntc.MachineType] = ntc.NodeInfo
|
||||||
}
|
}
|
||||||
provider = testprovider.NewTestAutoprovisioningCloudProvider(onScaleUpFunc, nil, onCreateGroupFunc, nil, machineTypes, machineTemplates)
|
provider = testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(onScaleUpFunc).WithOnNodeGroupCreate(onCreateGroupFunc).WithMachineTypes(machineTypes).WithMachineTemplates(machineTemplates).Build()
|
||||||
} else {
|
} else {
|
||||||
provider = testprovider.NewTestCloudProvider(onScaleUpFunc, nil)
|
provider = testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(onScaleUpFunc).Build()
|
||||||
}
|
}
|
||||||
options := defaultOptions
|
options := defaultOptions
|
||||||
if config.Options != nil {
|
if config.Options != nil {
|
||||||
|
|
@ -1138,10 +1138,10 @@ func TestScaleUpUnhealthy(t *testing.T) {
|
||||||
podLister := kube_util.NewTestPodLister(pods)
|
podLister := kube_util.NewTestPodLister(pods)
|
||||||
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(func(nodeGroup string, increase int) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodeGroup string, increase int) error {
|
||||||
t.Fatalf("No expansion is expected, but increased %s by %d", nodeGroup, increase)
|
t.Fatalf("No expansion is expected, but increased %s by %d", nodeGroup, increase)
|
||||||
return nil
|
return nil
|
||||||
}, nil)
|
}).Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 5)
|
provider.AddNodeGroup("ng2", 1, 10, 5)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
|
|
@ -1184,9 +1184,9 @@ func TestBinpackingLimiter(t *testing.T) {
|
||||||
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
|
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
|
||||||
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(func(nodeGroup string, increase int) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodeGroup string, increase int) error {
|
||||||
return nil
|
return nil
|
||||||
}, nil)
|
}).Build()
|
||||||
|
|
||||||
options := defaultOptions
|
options := defaultOptions
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
|
|
@ -1242,10 +1242,10 @@ func TestScaleUpNoHelp(t *testing.T) {
|
||||||
podLister := kube_util.NewTestPodLister(pods)
|
podLister := kube_util.NewTestPodLister(pods)
|
||||||
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(func(nodeGroup string, increase int) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodeGroup string, increase int) error {
|
||||||
t.Fatalf("No expansion is expected")
|
t.Fatalf("No expansion is expected")
|
||||||
return nil
|
return nil
|
||||||
}, nil)
|
}).Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
@ -1386,7 +1386,7 @@ func TestComputeSimilarNodeGroups(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(func(string, int) error { return nil }, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(string, int) error { return nil }).Build()
|
||||||
nodeGroupSetProcessor := &constNodeGroupSetProcessor{}
|
nodeGroupSetProcessor := &constNodeGroupSetProcessor{}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
|
|
@ -1451,9 +1451,9 @@ func TestScaleUpBalanceGroups(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(func(string, int) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(string, int) error {
|
||||||
return nil
|
return nil
|
||||||
}, nil)
|
}).Build()
|
||||||
|
|
||||||
type ngInfo struct {
|
type ngInfo struct {
|
||||||
min, max, size int
|
min, max, size int
|
||||||
|
|
@ -1544,14 +1544,13 @@ func TestScaleUpAutoprovisionedNodeGroup(t *testing.T) {
|
||||||
SetNodeReadyState(t1, true, time.Time{})
|
SetNodeReadyState(t1, true, time.Time{})
|
||||||
ti1 := framework.NewTestNodeInfo(t1)
|
ti1 := framework.NewTestNodeInfo(t1)
|
||||||
|
|
||||||
provider := testprovider.NewTestAutoprovisioningCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodeGroup string, increase int) error {
|
||||||
func(nodeGroup string, increase int) error {
|
expandedGroups <- fmt.Sprintf("%s-%d", nodeGroup, increase)
|
||||||
expandedGroups <- fmt.Sprintf("%s-%d", nodeGroup, increase)
|
return nil
|
||||||
return nil
|
}).WithOnNodeGroupCreate(func(nodeGroup string) error {
|
||||||
}, nil, func(nodeGroup string) error {
|
createdGroups <- nodeGroup
|
||||||
createdGroups <- nodeGroup
|
return nil
|
||||||
return nil
|
}).WithMachineTypes([]string{"T1"}).WithMachineTemplates(map[string]*framework.NodeInfo{"T1": ti1}).Build()
|
||||||
}, nil, []string{"T1"}, map[string]*framework.NodeInfo{"T1": ti1})
|
|
||||||
|
|
||||||
options := config.AutoscalingOptions{
|
options := config.AutoscalingOptions{
|
||||||
EstimatorName: estimator.BinpackingEstimatorName,
|
EstimatorName: estimator.BinpackingEstimatorName,
|
||||||
|
|
@ -1595,14 +1594,13 @@ func TestScaleUpBalanceAutoprovisionedNodeGroups(t *testing.T) {
|
||||||
SetNodeReadyState(t1, true, time.Time{})
|
SetNodeReadyState(t1, true, time.Time{})
|
||||||
ti1 := framework.NewTestNodeInfo(t1)
|
ti1 := framework.NewTestNodeInfo(t1)
|
||||||
|
|
||||||
provider := testprovider.NewTestAutoprovisioningCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodeGroup string, increase int) error {
|
||||||
func(nodeGroup string, increase int) error {
|
expandedGroups <- fmt.Sprintf("%s-%d", nodeGroup, increase)
|
||||||
expandedGroups <- fmt.Sprintf("%s-%d", nodeGroup, increase)
|
return nil
|
||||||
return nil
|
}).WithOnNodeGroupCreate(func(nodeGroup string) error {
|
||||||
}, nil, func(nodeGroup string) error {
|
createdGroups <- nodeGroup
|
||||||
createdGroups <- nodeGroup
|
return nil
|
||||||
return nil
|
}).WithMachineTypes([]string{"T1"}).WithMachineTemplates(map[string]*framework.NodeInfo{"T1": ti1}).Build()
|
||||||
}, nil, []string{"T1"}, map[string]*framework.NodeInfo{"T1": ti1})
|
|
||||||
|
|
||||||
options := config.AutoscalingOptions{
|
options := config.AutoscalingOptions{
|
||||||
BalanceSimilarNodeGroups: true,
|
BalanceSimilarNodeGroups: true,
|
||||||
|
|
@ -1642,11 +1640,11 @@ func TestScaleUpBalanceAutoprovisionedNodeGroups(t *testing.T) {
|
||||||
func TestScaleUpToMeetNodeGroupMinSize(t *testing.T) {
|
func TestScaleUpToMeetNodeGroupMinSize(t *testing.T) {
|
||||||
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
|
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
|
||||||
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
||||||
provider := testprovider.NewTestCloudProvider(func(nodeGroup string, increase int) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodeGroup string, increase int) error {
|
||||||
assert.Equal(t, "ng1", nodeGroup)
|
assert.Equal(t, "ng1", nodeGroup)
|
||||||
assert.Equal(t, 1, increase)
|
assert.Equal(t, 1, increase)
|
||||||
return nil
|
return nil
|
||||||
}, nil)
|
}).Build()
|
||||||
resourceLimiter := cloudprovider.NewResourceLimiter(
|
resourceLimiter := cloudprovider.NewResourceLimiter(
|
||||||
map[string]int64{cloudprovider.ResourceNameCores: 0, cloudprovider.ResourceNameMemory: 0},
|
map[string]int64{cloudprovider.ResourceNameCores: 0, cloudprovider.ResourceNameMemory: 0},
|
||||||
map[string]int64{cloudprovider.ResourceNameCores: 48, cloudprovider.ResourceNameMemory: 1000},
|
map[string]int64{cloudprovider.ResourceNameCores: 48, cloudprovider.ResourceNameMemory: 1000},
|
||||||
|
|
@ -1743,14 +1741,13 @@ func TestScaleupAsyncNodeGroupsEnabled(t *testing.T) {
|
||||||
expandedGroups := make(map[string]int)
|
expandedGroups := make(map[string]int)
|
||||||
fakeClient := &fake.Clientset{}
|
fakeClient := &fake.Clientset{}
|
||||||
|
|
||||||
provider := testprovider.NewTestAutoprovisioningCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodeGroup string, increase int) error {
|
||||||
func(nodeGroup string, increase int) error {
|
expandedGroups[nodeGroup] += increase
|
||||||
expandedGroups[nodeGroup] += increase
|
return nil
|
||||||
return nil
|
}).WithOnNodeGroupCreate(func(nodeGroup string) error {
|
||||||
}, nil, func(nodeGroup string) error {
|
createdGroups[nodeGroup] = true
|
||||||
createdGroups[nodeGroup] = true
|
return nil
|
||||||
return nil
|
}).WithMachineTypes(tc.machineTypes).WithMachineTemplates(tc.machineTemplates).Build()
|
||||||
}, nil, tc.machineTypes, tc.machineTemplates)
|
|
||||||
|
|
||||||
for _, upcomingNodeName := range tc.upcomingNodeGroupsNames {
|
for _, upcomingNodeName := range tc.upcomingNodeGroupsNames {
|
||||||
provider.AddNodeGroup(upcomingNodeName, 0, 10, 0)
|
provider.AddNodeGroup(upcomingNodeName, 0, 10, 0)
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ func TestDeltaForNode(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
cp := testprovider.NewTestCloudProvider(nil, nil)
|
cp := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
ctx := newContext(t, cp)
|
ctx := newContext(t, cp)
|
||||||
processors := processorstest.NewTestProcessors(&ctx)
|
processors := processorstest.NewTestProcessors(&ctx)
|
||||||
|
|
||||||
|
|
@ -162,7 +162,7 @@ func TestApplyLimits(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
cp := testprovider.NewTestCloudProvider(nil, nil)
|
cp := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
ctx := newContext(t, cp)
|
ctx := newContext(t, cp)
|
||||||
processors := processorstest.NewTestProcessors(&ctx)
|
processors := processorstest.NewTestProcessors(&ctx)
|
||||||
|
|
||||||
|
|
@ -216,7 +216,7 @@ func TestCheckDeltaWithinLimits(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResourceManagerWithGpuResource(t *testing.T) {
|
func TestResourceManagerWithGpuResource(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
resourceLimiter := cloudprovider.NewResourceLimiter(
|
resourceLimiter := cloudprovider.NewResourceLimiter(
|
||||||
map[string]int64{cloudprovider.ResourceNameCores: 0, cloudprovider.ResourceNameMemory: 0, "gpu": 0},
|
map[string]int64{cloudprovider.ResourceNameCores: 0, cloudprovider.ResourceNameMemory: 0, "gpu": 0},
|
||||||
map[string]int64{cloudprovider.ResourceNameCores: 320, cloudprovider.ResourceNameMemory: 640, "gpu": 16},
|
map[string]int64{cloudprovider.ResourceNameCores: 320, cloudprovider.ResourceNameMemory: 640, "gpu": 16},
|
||||||
|
|
@ -259,7 +259,7 @@ func TestResourceManagerWithGpuResource(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCloudProvider(t *testing.T, cpu, mem int64) *testprovider.TestCloudProvider {
|
func newCloudProvider(t *testing.T, cpu, mem int64) *testprovider.TestCloudProvider {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
||||||
resourceLimiter := cloudprovider.NewResourceLimiter(
|
resourceLimiter := cloudprovider.NewResourceLimiter(
|
||||||
|
|
|
||||||
|
|
@ -245,14 +245,13 @@ type autoscalerSetupConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupCloudProvider(config *autoscalerSetupConfig) (*testprovider.TestCloudProvider, error) {
|
func setupCloudProvider(config *autoscalerSetupConfig) (*testprovider.TestCloudProvider, error) {
|
||||||
provider := testprovider.NewTestCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(id string, delta int) error {
|
||||||
func(id string, delta int) error {
|
return config.mocks.onScaleUp.ScaleUp(id, delta)
|
||||||
return config.mocks.onScaleUp.ScaleUp(id, delta)
|
}).WithOnScaleDown(func(id string, name string) error {
|
||||||
}, func(id string, name string) error {
|
ret := config.mocks.onScaleDown.ScaleDown(id, name)
|
||||||
ret := config.mocks.onScaleDown.ScaleDown(id, name)
|
config.nodesDeleted <- true
|
||||||
config.nodesDeleted <- true
|
return ret
|
||||||
return ret
|
}).Build()
|
||||||
})
|
|
||||||
nodeGroupTemplates := map[string]*framework.NodeInfo{}
|
nodeGroupTemplates := map[string]*framework.NodeInfo{}
|
||||||
for _, ng := range config.nodeGroups {
|
for _, ng := range config.nodeGroups {
|
||||||
provider.AddNodeGroup(ng.name, ng.min, ng.max, len(ng.nodes))
|
provider.AddNodeGroup(ng.name, ng.min, ng.max, len(ng.nodes))
|
||||||
|
|
@ -366,16 +365,13 @@ func TestStaticAutoscalerRunOnce(t *testing.T) {
|
||||||
tn := BuildTestNode("tn", 1000, 1000)
|
tn := BuildTestNode("tn", 1000, 1000)
|
||||||
tni := framework.NewTestNodeInfo(tn)
|
tni := framework.NewTestNodeInfo(tn)
|
||||||
|
|
||||||
provider := testprovider.NewTestAutoprovisioningCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(id string, delta int) error {
|
||||||
func(id string, delta int) error {
|
return onScaleUpMock.ScaleUp(id, delta)
|
||||||
return onScaleUpMock.ScaleUp(id, delta)
|
}).WithOnScaleDown(func(id string, name string) error {
|
||||||
}, func(id string, name string) error {
|
ret := onScaleDownMock.ScaleDown(id, name)
|
||||||
ret := onScaleDownMock.ScaleDown(id, name)
|
deleteFinished <- true
|
||||||
deleteFinished <- true
|
return ret
|
||||||
return ret
|
}).WithMachineTemplates(map[string]*framework.NodeInfo{"ng1": tni, "ng2": tni, "ng3": tni}).Build()
|
||||||
},
|
|
||||||
nil, nil,
|
|
||||||
nil, map[string]*framework.NodeInfo{"ng1": tni, "ng2": tni, "ng3": tni})
|
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
ng1 := reflect.ValueOf(provider.GetNodeGroup("ng1")).Interface().(*testprovider.TestNodeGroup)
|
ng1 := reflect.ValueOf(provider.GetNodeGroup("ng1")).Interface().(*testprovider.TestNodeGroup)
|
||||||
|
|
@ -538,16 +534,13 @@ func TestStaticAutoscalerRunOnceWithScaleDownDelayPerNG(t *testing.T) {
|
||||||
tn := BuildTestNode("tn", 1000, 1000)
|
tn := BuildTestNode("tn", 1000, 1000)
|
||||||
tni := framework.NewTestNodeInfo(tn)
|
tni := framework.NewTestNodeInfo(tn)
|
||||||
|
|
||||||
provider := testprovider.NewTestAutoprovisioningCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(id string, delta int) error {
|
||||||
func(id string, delta int) error {
|
return onScaleUpMock.ScaleUp(id, delta)
|
||||||
return onScaleUpMock.ScaleUp(id, delta)
|
}).WithOnScaleDown(func(id string, name string) error {
|
||||||
}, func(id string, name string) error {
|
ret := onScaleDownMock.ScaleDown(id, name)
|
||||||
ret := onScaleDownMock.ScaleDown(id, name)
|
deleteFinished <- true
|
||||||
deleteFinished <- true
|
return ret
|
||||||
return ret
|
}).WithMachineTemplates(map[string]*framework.NodeInfo{"ng1": tni, "ng2": tni}).Build()
|
||||||
},
|
|
||||||
nil, nil,
|
|
||||||
nil, map[string]*framework.NodeInfo{"ng1": tni, "ng2": tni})
|
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
||||||
provider.AddNodeGroup("ng1", 0, 10, 1)
|
provider.AddNodeGroup("ng1", 0, 10, 1)
|
||||||
|
|
@ -778,19 +771,14 @@ func TestStaticAutoscalerRunOnceWithAutoprovisionedEnabled(t *testing.T) {
|
||||||
SetNodeReadyState(tn2, true, time.Now())
|
SetNodeReadyState(tn2, true, time.Now())
|
||||||
tni3 := framework.NewTestNodeInfo(tn3)
|
tni3 := framework.NewTestNodeInfo(tn3)
|
||||||
|
|
||||||
provider := testprovider.NewTestAutoprovisioningCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(id string, delta int) error {
|
||||||
func(id string, delta int) error {
|
return onScaleUpMock.ScaleUp(id, delta)
|
||||||
return onScaleUpMock.ScaleUp(id, delta)
|
}).WithOnScaleDown(func(id string, name string) error {
|
||||||
}, func(id string, name string) error {
|
ret := onScaleDownMock.ScaleDown(id, name)
|
||||||
ret := onScaleDownMock.ScaleDown(id, name)
|
deleteFinished <- true
|
||||||
deleteFinished <- true
|
return ret
|
||||||
return ret
|
}).WithOnNodeGroupCreate(onNodeGroupCreateMock.Create).WithOnNodeGroupDelete(onNodeGroupDeleteMock.Delete).
|
||||||
}, func(id string) error {
|
WithMachineTypes([]string{"TN1", "TN2"}).WithMachineTemplates(map[string]*framework.NodeInfo{"TN1": tni1, "TN2": tni2, "ng1": tni3}).Build()
|
||||||
return onNodeGroupCreateMock.Create(id)
|
|
||||||
}, func(id string) error {
|
|
||||||
return onNodeGroupDeleteMock.Delete(id)
|
|
||||||
},
|
|
||||||
[]string{"TN1", "TN2"}, map[string]*framework.NodeInfo{"TN1": tni1, "TN2": tni2, "ng1": tni3})
|
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddAutoprovisionedNodeGroup("autoprovisioned-TN1", 0, 10, 0, "TN1")
|
provider.AddAutoprovisionedNodeGroup("autoprovisioned-TN1", 0, 10, 0, "TN1")
|
||||||
autoprovisionedTN1 := reflect.ValueOf(provider.GetNodeGroup("autoprovisioned-TN1")).Interface().(*testprovider.TestNodeGroup)
|
autoprovisionedTN1 := reflect.ValueOf(provider.GetNodeGroup("autoprovisioned-TN1")).Interface().(*testprovider.TestNodeGroup)
|
||||||
|
|
@ -925,14 +913,13 @@ func TestStaticAutoscalerRunOnceWithALongUnregisteredNode(t *testing.T) {
|
||||||
p1.Spec.NodeName = "n1"
|
p1.Spec.NodeName = "n1"
|
||||||
p2 := BuildTestPod("p2", 600, 100, MarkUnschedulable())
|
p2 := BuildTestPod("p2", 600, 100, MarkUnschedulable())
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(id string, delta int) error {
|
||||||
func(id string, delta int) error {
|
return onScaleUpMock.ScaleUp(id, delta)
|
||||||
return onScaleUpMock.ScaleUp(id, delta)
|
}).WithOnScaleDown(func(id string, name string) error {
|
||||||
}, func(id string, name string) error {
|
ret := onScaleDownMock.ScaleDown(id, name)
|
||||||
ret := onScaleDownMock.ScaleDown(id, name)
|
deleteFinished <- true
|
||||||
deleteFinished <- true
|
return ret
|
||||||
return ret
|
}).Build()
|
||||||
})
|
|
||||||
provider.AddNodeGroup("ng1", 2, 10, 2)
|
provider.AddNodeGroup("ng1", 2, 10, 2)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
|
|
||||||
|
|
@ -1092,14 +1079,13 @@ func TestStaticAutoscalerRunOncePodsWithPriorities(t *testing.T) {
|
||||||
p6.OwnerReferences = ownerRef
|
p6.OwnerReferences = ownerRef
|
||||||
p6.Spec.Priority = &priority100
|
p6.Spec.Priority = &priority100
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(id string, delta int) error {
|
||||||
func(id string, delta int) error {
|
return onScaleUpMock.ScaleUp(id, delta)
|
||||||
return onScaleUpMock.ScaleUp(id, delta)
|
}).WithOnScaleDown(func(id string, name string) error {
|
||||||
}, func(id string, name string) error {
|
ret := onScaleDownMock.ScaleDown(id, name)
|
||||||
ret := onScaleDownMock.ScaleDown(id, name)
|
deleteFinished <- true
|
||||||
deleteFinished <- true
|
return ret
|
||||||
return ret
|
}).Build()
|
||||||
})
|
|
||||||
provider.AddNodeGroup("ng1", 0, 10, 1)
|
provider.AddNodeGroup("ng1", 0, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 0, 10, 2)
|
provider.AddNodeGroup("ng2", 0, 10, 2)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
|
|
@ -1230,12 +1216,11 @@ func TestStaticAutoscalerRunOnceWithFilteringOnBinPackingEstimator(t *testing.T)
|
||||||
p4.Spec.NodeName = "n2"
|
p4.Spec.NodeName = "n2"
|
||||||
p4.OwnerReferences = ownerRef
|
p4.OwnerReferences = ownerRef
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(id string, delta int) error {
|
||||||
func(id string, delta int) error {
|
return onScaleUpMock.ScaleUp(id, delta)
|
||||||
return onScaleUpMock.ScaleUp(id, delta)
|
}).WithOnScaleDown(func(id string, name string) error {
|
||||||
}, func(id string, name string) error {
|
return onScaleDownMock.ScaleDown(id, name)
|
||||||
return onScaleDownMock.ScaleDown(id, name)
|
}).Build()
|
||||||
})
|
|
||||||
provider.AddNodeGroup("ng1", 0, 10, 2)
|
provider.AddNodeGroup("ng1", 0, 10, 2)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
|
|
||||||
|
|
@ -1329,12 +1314,11 @@ func TestStaticAutoscalerRunOnceWithFilteringOnUpcomingNodesEnabledNoScaleUp(t *
|
||||||
p3.Spec.NodeName = "n3"
|
p3.Spec.NodeName = "n3"
|
||||||
p3.OwnerReferences = ownerRef
|
p3.OwnerReferences = ownerRef
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(id string, delta int) error {
|
||||||
func(id string, delta int) error {
|
return onScaleUpMock.ScaleUp(id, delta)
|
||||||
return onScaleUpMock.ScaleUp(id, delta)
|
}).WithOnScaleDown(func(id string, name string) error {
|
||||||
}, func(id string, name string) error {
|
return onScaleDownMock.ScaleDown(id, name)
|
||||||
return onScaleDownMock.ScaleDown(id, name)
|
}).Build()
|
||||||
})
|
|
||||||
provider.AddNodeGroup("ng1", 0, 10, 2)
|
provider.AddNodeGroup("ng1", 0, 10, 2)
|
||||||
provider.AddNode("ng1", n2)
|
provider.AddNode("ng1", n2)
|
||||||
|
|
||||||
|
|
@ -1423,7 +1407,7 @@ func TestStaticAutoscalerRunOnceWithUnselectedNodeGroups(t *testing.T) {
|
||||||
p1.Spec.NodeName = n1.Name
|
p1.Spec.NodeName = n1.Name
|
||||||
|
|
||||||
// set minimal cloud provider where only ng1 is defined as selected node group
|
// set minimal cloud provider where only ng1 is defined as selected node group
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
assert.NotNil(t, provider)
|
assert.NotNil(t, provider)
|
||||||
|
|
@ -2026,7 +2010,7 @@ func TestStaticAutoscalerUpcomingScaleDownCandidates(t *testing.T) {
|
||||||
startTime := time.Time{}
|
startTime := time.Time{}
|
||||||
|
|
||||||
// Generate a number of ready and unready nodes created at startTime, spread across multiple node groups.
|
// Generate a number of ready and unready nodes created at startTime, spread across multiple node groups.
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
allNodeNames := map[string]bool{}
|
allNodeNames := map[string]bool{}
|
||||||
readyNodeNames := map[string]bool{}
|
readyNodeNames := map[string]bool{}
|
||||||
notReadyNodeNames := map[string]bool{}
|
notReadyNodeNames := map[string]bool{}
|
||||||
|
|
@ -2161,10 +2145,10 @@ func TestRemoveFixNodeTargetSize(t *testing.T) {
|
||||||
|
|
||||||
ng1_1 := BuildTestNode("ng1-1", 1000, 1000)
|
ng1_1 := BuildTestNode("ng1-1", 1000, 1000)
|
||||||
ng1_1.Spec.ProviderID = "ng1-1"
|
ng1_1.Spec.ProviderID = "ng1-1"
|
||||||
provider := testprovider.NewTestCloudProvider(func(nodegroup string, delta int) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(nodegroup string, delta int) error {
|
||||||
sizeChanges <- fmt.Sprintf("%s/%d", nodegroup, delta)
|
sizeChanges <- fmt.Sprintf("%s/%d", nodegroup, delta)
|
||||||
return nil
|
return nil
|
||||||
}, nil)
|
}).Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 3)
|
provider.AddNodeGroup("ng1", 1, 10, 3)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
|
|
||||||
|
|
@ -2209,10 +2193,10 @@ func TestRemoveOldUnregisteredNodes(t *testing.T) {
|
||||||
ng1_1.Spec.ProviderID = "ng1-1"
|
ng1_1.Spec.ProviderID = "ng1-1"
|
||||||
ng1_2 := BuildTestNode("ng1-2", 1000, 1000)
|
ng1_2 := BuildTestNode("ng1-2", 1000, 1000)
|
||||||
ng1_2.Spec.ProviderID = "ng1-2"
|
ng1_2.Spec.ProviderID = "ng1-2"
|
||||||
provider := testprovider.NewTestCloudProvider(nil, func(nodegroup string, node string) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleDown(func(nodegroup string, node string) error {
|
||||||
deletedNodes <- fmt.Sprintf("%s/%s", nodegroup, node)
|
deletedNodes <- fmt.Sprintf("%s/%s", nodegroup, node)
|
||||||
return nil
|
return nil
|
||||||
})
|
}).Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 2)
|
provider.AddNodeGroup("ng1", 1, 10, 2)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
provider.AddNode("ng1", ng1_2)
|
provider.AddNode("ng1", ng1_2)
|
||||||
|
|
@ -2260,10 +2244,10 @@ func TestRemoveOldUnregisteredNodesAtomic(t *testing.T) {
|
||||||
deletedNodes := make(chan string, 10)
|
deletedNodes := make(chan string, 10)
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
provider := testprovider.NewTestCloudProvider(nil, func(nodegroup string, node string) error {
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleDown(func(nodegroup string, node string) error {
|
||||||
deletedNodes <- fmt.Sprintf("%s/%s", nodegroup, node)
|
deletedNodes <- fmt.Sprintf("%s/%s", nodegroup, node)
|
||||||
return nil
|
return nil
|
||||||
})
|
}).Build()
|
||||||
provider.AddNodeGroupWithCustomOptions("atomic-ng", 0, 10, 10, &config.NodeGroupAutoscalingOptions{
|
provider.AddNodeGroupWithCustomOptions("atomic-ng", 0, 10, 10, &config.NodeGroupAutoscalingOptions{
|
||||||
MaxNodeProvisionTime: 45 * time.Minute,
|
MaxNodeProvisionTime: 45 * time.Minute,
|
||||||
ZeroOrMaxNodeScaling: true,
|
ZeroOrMaxNodeScaling: true,
|
||||||
|
|
@ -2736,7 +2720,7 @@ func newEstimatorBuilder() estimator.EstimatorBuilder {
|
||||||
|
|
||||||
func TestCleaningSoftTaintsInScaleDown(t *testing.T) {
|
func TestCleaningSoftTaintsInScaleDown(t *testing.T) {
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
|
|
||||||
minSizeNgName := "ng-min-size"
|
minSizeNgName := "ng-min-size"
|
||||||
nodesToHaveNoTaints := createNodeGroupWithSoftTaintedNodes(provider, minSizeNgName, 2, 10, 2)
|
nodesToHaveNoTaints := createNodeGroupWithSoftTaintedNodes(provider, minSizeNgName, 2, 10, 2)
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ func TestSngCapacityThreshold(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(func(string, int) error { return nil }, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(func(string, int) error { return nil }).Build()
|
||||||
for _, ng := range tt.nodeGroupsConfig {
|
for _, ng := range tt.nodeGroupsConfig {
|
||||||
provider.AddNodeGroup(ng.name, 0, ng.maxNodes, ng.nodesCount)
|
provider.AddNodeGroup(ng.name, 0, ng.maxNodes, ng.nodesCount)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ func TestPriceExpander(t *testing.T) {
|
||||||
p1 := BuildTestPod("p1", 1000, 0)
|
p1 := BuildTestPod("p1", 1000, 0)
|
||||||
p2 := BuildTestPod("p2", 500, 0)
|
p2 := BuildTestPod("p2", 500, 0)
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ func TestFilterOutNodesWithUnreadyResources(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
processor := NewDefaultCustomResourcesProcessor()
|
processor := NewDefaultCustomResourcesProcessor()
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
ctx := &context.AutoscalingContext{CloudProvider: provider}
|
ctx := &context.AutoscalingContext{CloudProvider: provider}
|
||||||
newAllNodes, newReadyNodes := processor.FilterOutNodesWithUnreadyResources(ctx, initialAllNodes, initialReadyNodes)
|
newAllNodes, newReadyNodes := processor.FilterOutNodesWithUnreadyResources(ctx, initialAllNodes, initialReadyNodes)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ func TestFindSimilarNodeGroupsAzureByLabel(t *testing.T) {
|
||||||
n1 := BuildTestNode("n1", 1000, 1000)
|
n1 := BuildTestNode("n1", 1000, 1000)
|
||||||
n2 := BuildTestNode("n2", 2000, 2000)
|
n2 := BuildTestNode("n2", 2000, 2000)
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNode("ng1", n1)
|
provider.AddNode("ng1", n1)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func buildBasicNodeGroups(context *context.AutoscalingContext) (*framework.NodeI
|
||||||
n1 := BuildTestNode("n1", 1000, 1000)
|
n1 := BuildTestNode("n1", 1000, 1000)
|
||||||
n2 := BuildTestNode("n2", 1000, 1000)
|
n2 := BuildTestNode("n2", 1000, 1000)
|
||||||
n3 := BuildTestNode("n3", 2000, 2000)
|
n3 := BuildTestNode("n3", 2000, 2000)
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng3", 1, 10, 1)
|
provider.AddNodeGroup("ng3", 1, 10, 1)
|
||||||
|
|
@ -112,7 +112,7 @@ func TestBalanceSingleGroup(t *testing.T) {
|
||||||
processor := NewDefaultNodeGroupSetProcessor([]string{}, config.NodeGroupDifferenceRatios{})
|
processor := NewDefaultNodeGroupSetProcessor([]string{}, config.NodeGroupDifferenceRatios{})
|
||||||
context := &context.AutoscalingContext{}
|
context := &context.AutoscalingContext{}
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
|
|
||||||
// just one node
|
// just one node
|
||||||
|
|
@ -132,7 +132,7 @@ func TestBalanceUnderMaxSize(t *testing.T) {
|
||||||
processor := NewDefaultNodeGroupSetProcessor([]string{}, config.NodeGroupDifferenceRatios{})
|
processor := NewDefaultNodeGroupSetProcessor([]string{}, config.NodeGroupDifferenceRatios{})
|
||||||
context := &context.AutoscalingContext{}
|
context := &context.AutoscalingContext{}
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 1)
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 3)
|
provider.AddNodeGroup("ng2", 1, 10, 3)
|
||||||
provider.AddNodeGroup("ng3", 1, 10, 5)
|
provider.AddNodeGroup("ng3", 1, 10, 5)
|
||||||
|
|
@ -182,7 +182,7 @@ func TestBalanceHittingMaxSize(t *testing.T) {
|
||||||
processor := NewDefaultNodeGroupSetProcessor([]string{}, config.NodeGroupDifferenceRatios{})
|
processor := NewDefaultNodeGroupSetProcessor([]string{}, config.NodeGroupDifferenceRatios{})
|
||||||
context := &context.AutoscalingContext{}
|
context := &context.AutoscalingContext{}
|
||||||
|
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 1, 1)
|
provider.AddNodeGroup("ng1", 1, 1, 1)
|
||||||
provider.AddNodeGroup("ng2", 1, 3, 1)
|
provider.AddNodeGroup("ng2", 1, 3, 1)
|
||||||
provider.AddNodeGroup("ng3", 1, 10, 3)
|
provider.AddNodeGroup("ng3", 1, 10, 3)
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,8 @@ func TestGetNodeInfosForGroups(t *testing.T) {
|
||||||
tni := framework.NewTestNodeInfo(tn)
|
tni := framework.NewTestNodeInfo(tn)
|
||||||
|
|
||||||
// Cloud provider with TemplateNodeInfo implemented.
|
// Cloud provider with TemplateNodeInfo implemented.
|
||||||
provider1 := testprovider.NewTestAutoprovisioningCloudProvider(
|
provider1 := testprovider.NewTestCloudProviderBuilder().WithMachineTemplates(
|
||||||
nil, nil, nil, nil, nil,
|
map[string]*framework.NodeInfo{"ng3": tni, "ng4": tni, "ng5": tni, "ng6": tni}).Build()
|
||||||
map[string]*framework.NodeInfo{"ng3": tni, "ng4": tni, "ng5": tni, "ng6": tni})
|
|
||||||
provider1.AddNodeGroup("ng1", 1, 10, 1) // Nodegroup with ready node.
|
provider1.AddNodeGroup("ng1", 1, 10, 1) // Nodegroup with ready node.
|
||||||
provider1.AddNode("ng1", ready1)
|
provider1.AddNode("ng1", ready1)
|
||||||
provider1.AddNodeGroup("ng2", 1, 10, 1) // Nodegroup with ready and unready node.
|
provider1.AddNodeGroup("ng2", 1, 10, 1) // Nodegroup with ready and unready node.
|
||||||
|
|
@ -79,7 +78,7 @@ func TestGetNodeInfosForGroups(t *testing.T) {
|
||||||
provider1.AddNode("ng6", ready7)
|
provider1.AddNode("ng6", ready7)
|
||||||
|
|
||||||
// Cloud provider with TemplateNodeInfo not implemented.
|
// Cloud provider with TemplateNodeInfo not implemented.
|
||||||
provider2 := testprovider.NewTestAutoprovisioningCloudProvider(nil, nil, nil, nil, nil, nil)
|
provider2 := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider2.AddNodeGroup("ng7", 1, 10, 1) // Nodegroup without nodes.
|
provider2.AddNodeGroup("ng7", 1, 10, 1) // Nodegroup without nodes.
|
||||||
|
|
||||||
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
|
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
|
||||||
|
|
@ -157,9 +156,7 @@ func TestGetNodeInfosForGroupsCache(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cloud provider with TemplateNodeInfo implemented.
|
// Cloud provider with TemplateNodeInfo implemented.
|
||||||
provider1 := testprovider.NewTestAutoprovisioningCloudProvider(
|
provider1 := testprovider.NewTestCloudProviderBuilder().WithOnNodeGroupDelete(onDeleteGroup).WithMachineTemplates(map[string]*framework.NodeInfo{"ng3": tni, "ng4": tni}).Build()
|
||||||
nil, nil, nil, onDeleteGroup, nil,
|
|
||||||
map[string]*framework.NodeInfo{"ng3": tni, "ng4": tni})
|
|
||||||
provider1.AddNodeGroup("ng1", 1, 10, 1) // Nodegroup with ready node.
|
provider1.AddNodeGroup("ng1", 1, 10, 1) // Nodegroup with ready node.
|
||||||
provider1.AddNode("ng1", ready1)
|
provider1.AddNode("ng1", ready1)
|
||||||
provider1.AddNodeGroup("ng2", 1, 10, 1) // Nodegroup with ready and unready node.
|
provider1.AddNodeGroup("ng2", 1, 10, 1) // Nodegroup with ready and unready node.
|
||||||
|
|
@ -261,7 +258,7 @@ func TestGetNodeInfosCacheExpired(t *testing.T) {
|
||||||
SetNodeReadyState(ready1, true, now.Add(-2*time.Minute))
|
SetNodeReadyState(ready1, true, now.Add(-2*time.Minute))
|
||||||
|
|
||||||
// Cloud provider with TemplateNodeInfo not implemented.
|
// Cloud provider with TemplateNodeInfo not implemented.
|
||||||
provider := testprovider.NewTestAutoprovisioningCloudProvider(nil, nil, nil, nil, nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
|
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
|
||||||
registry := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
registry := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ func TestPreFilteringScaleDownNodeProcessor_GetScaleDownCandidateNodes(t *testin
|
||||||
ng1_2 := BuildTestNode("ng1-2", 1000, 1000)
|
ng1_2 := BuildTestNode("ng1-2", 1000, 1000)
|
||||||
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
ng2_1 := BuildTestNode("ng2-1", 1000, 1000)
|
||||||
noNg := BuildTestNode("no-ng", 1000, 1000)
|
noNg := BuildTestNode("no-ng", 1000, 1000)
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup("ng1", 1, 10, 2)
|
provider.AddNodeGroup("ng1", 1, 10, 2)
|
||||||
provider.AddNodeGroup("ng2", 1, 10, 1)
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
||||||
provider.AddNode("ng1", ng1_1)
|
provider.AddNode("ng1", ng1_1)
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ func TestAtomicResizeFilterUnremovableNodes(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
processor := NewAtomicResizeFilteringProcessor()
|
processor := NewAtomicResizeFilteringProcessor()
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
for _, ng := range tc.nodeGroups {
|
for _, ng := range tc.nodeGroups {
|
||||||
provider.AddNodeGroupWithCustomOptions(ng.nodeGroupName, 0, 100, ng.nodeGroupTargetSize, &config.NodeGroupAutoscalingOptions{
|
provider.AddNodeGroupWithCustomOptions(ng.nodeGroupName, 0, 100, ng.nodeGroupTargetSize, &config.NodeGroupAutoscalingOptions{
|
||||||
ZeroOrMaxNodeScaling: ng.zeroOrMaxNodeScaling,
|
ZeroOrMaxNodeScaling: ng.zeroOrMaxNodeScaling,
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ func TestGetScaleDownCandidates(t *testing.T) {
|
||||||
|
|
||||||
for description, testCase := range testCases {
|
for description, testCase := range testCases {
|
||||||
t.Run(description, func(t *testing.T) {
|
t.Run(description, func(t *testing.T) {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
|
|
||||||
p := NewScaleDownCandidatesDelayProcessor()
|
p := NewScaleDownCandidatesDelayProcessor()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -459,7 +459,7 @@ func TestScaleUp(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTest(t *testing.T, client *provreqclient.ProvisioningRequestClient, nodes []*apiv1.Node, onScaleUpFunc func(string, int) error, autoprovisioning bool, batchProcessing bool, maxBatchSize int, batchTimebox time.Duration) (*provReqOrchestrator, map[string]*framework.NodeInfo) {
|
func setupTest(t *testing.T, client *provreqclient.ProvisioningRequestClient, nodes []*apiv1.Node, onScaleUpFunc func(string, int) error, autoprovisioning bool, batchProcessing bool, maxBatchSize int, batchTimebox time.Duration) (*provReqOrchestrator, map[string]*framework.NodeInfo) {
|
||||||
provider := testprovider.NewTestCloudProvider(onScaleUpFunc, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(onScaleUpFunc).Build()
|
||||||
clock := clocktesting.NewFakePassiveClock(time.Now())
|
clock := clocktesting.NewFakePassiveClock(time.Now())
|
||||||
now := clock.Now()
|
now := clock.Now()
|
||||||
if autoprovisioning {
|
if autoprovisioning {
|
||||||
|
|
@ -471,7 +471,7 @@ func setupTest(t *testing.T, client *provreqclient.ProvisioningRequestClient, no
|
||||||
"large-machine": nodeInfoTemplate,
|
"large-machine": nodeInfoTemplate,
|
||||||
}
|
}
|
||||||
onNodeGroupCreateFunc := func(name string) error { return nil }
|
onNodeGroupCreateFunc := func(name string) error { return nil }
|
||||||
provider = testprovider.NewTestAutoprovisioningCloudProvider(onScaleUpFunc, nil, onNodeGroupCreateFunc, nil, machineTypes, machineTemplates)
|
provider = testprovider.NewTestCloudProviderBuilder().WithOnScaleUp(onScaleUpFunc).WithOnNodeGroupCreate(onNodeGroupCreateFunc).WithMachineTypes(machineTypes).WithMachineTemplates(machineTemplates).Build()
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.AddNodeGroup("test-cpu", 50, 150, 100)
|
provider.AddNodeGroup("test-cpu", 50, 150, 100)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func nodeGroup(id string) cloudprovider.NodeGroup {
|
func nodeGroup(id string) cloudprovider.NodeGroup {
|
||||||
provider := testprovider.NewTestCloudProvider(nil, nil)
|
provider := testprovider.NewTestCloudProviderBuilder().Build()
|
||||||
provider.AddNodeGroup(id, 1, 10, 1)
|
provider.AddNodeGroup(id, 1, 10, 1)
|
||||||
return provider.GetNodeGroup(id)
|
return provider.GetNodeGroup(id)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue