69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
/*
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package nodegroupset
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
|
|
testprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/test"
|
|
. "k8s.io/autoscaler/cluster-autoscaler/utils/test"
|
|
"k8s.io/kubernetes/plugin/pkg/scheduler/schedulercache"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFindSimilarNodeGroups(t *testing.T) {
|
|
n1 := BuildTestNode("n1", 1000, 1000)
|
|
n2 := BuildTestNode("n2", 1000, 1000)
|
|
n3 := BuildTestNode("n3", 2000, 2000)
|
|
provider := testprovider.NewTestCloudProvider(nil, nil)
|
|
provider.AddNodeGroup("ng1", 1, 10, 1)
|
|
provider.AddNodeGroup("ng2", 1, 10, 1)
|
|
provider.AddNodeGroup("ng3", 1, 10, 1)
|
|
provider.AddNode("ng1", n1)
|
|
provider.AddNode("ng2", n2)
|
|
provider.AddNode("ng3", n3)
|
|
|
|
ni1 := schedulercache.NewNodeInfo()
|
|
ni1.SetNode(n1)
|
|
ni2 := schedulercache.NewNodeInfo()
|
|
ni2.SetNode(n2)
|
|
ni3 := schedulercache.NewNodeInfo()
|
|
ni3.SetNode(n3)
|
|
|
|
nodeInfosForGroups := map[string]*schedulercache.NodeInfo{
|
|
"ng1": ni1, "ng2": ni2, "ng3": ni3,
|
|
}
|
|
|
|
ng1, _ := provider.NodeGroupForNode(n1)
|
|
ng2, _ := provider.NodeGroupForNode(n2)
|
|
ng3, _ := provider.NodeGroupForNode(n3)
|
|
|
|
similar, err := FindSimilarNodeGroups(ng1, provider, nodeInfosForGroups)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, similar, []cloudprovider.NodeGroup{ng2})
|
|
|
|
similar, err = FindSimilarNodeGroups(ng2, provider, nodeInfosForGroups)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, similar, []cloudprovider.NodeGroup{ng1})
|
|
|
|
similar, err = FindSimilarNodeGroups(ng3, provider, nodeInfosForGroups)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, similar, []cloudprovider.NodeGroup{})
|
|
}
|