mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Merge pull request #113505 from Abirdcfly/fixcomment
chore(scheduler): cleanup some minor issues in testing
This commit is contained in:
commit
1d2e804287
@ -645,11 +645,6 @@ func TestStorageRequests(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFitScore(t *testing.T) {
|
func TestFitScore(t *testing.T) {
|
||||||
defaultResources := []config.ResourceSpec{
|
|
||||||
{Name: string(v1.ResourceCPU), Weight: 1},
|
|
||||||
{Name: string(v1.ResourceMemory), Weight: 1},
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
requestedPod *v1.Pod
|
requestedPod *v1.Pod
|
||||||
|
@ -32,18 +32,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestLeastAllocatedScoringStrategy(t *testing.T) {
|
func TestLeastAllocatedScoringStrategy(t *testing.T) {
|
||||||
defaultResources := []config.ResourceSpec{
|
|
||||||
{Name: string(v1.ResourceCPU), Weight: 1},
|
|
||||||
{Name: string(v1.ResourceMemory), Weight: 1},
|
|
||||||
}
|
|
||||||
|
|
||||||
extendedRes := "abc.com/xyz"
|
|
||||||
extendedResourceLeastAllocatedSet := []config.ResourceSpec{
|
|
||||||
{Name: string(v1.ResourceCPU), Weight: 1},
|
|
||||||
{Name: string(v1.ResourceMemory), Weight: 1},
|
|
||||||
{Name: extendedRes, Weight: 1},
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
requestedPod *v1.Pod
|
requestedPod *v1.Pod
|
||||||
@ -347,7 +335,7 @@ func TestLeastAllocatedScoringStrategy(t *testing.T) {
|
|||||||
st.MakeNode().Name("node2").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000", v1.ResourceName(extendedRes): "4"}).Obj(),
|
st.MakeNode().Name("node2").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000", v1.ResourceName(extendedRes): "4"}).Obj(),
|
||||||
},
|
},
|
||||||
expectedScores: []framework.NodeScore{{Name: "node1", Score: 50}, {Name: "node2", Score: 50}},
|
expectedScores: []framework.NodeScore{{Name: "node1", Score: 50}, {Name: "node2", Score: 50}},
|
||||||
resources: extendedResourceLeastAllocatedSet,
|
resources: extendedResourceSet,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Honor extended resource if the pod requests.
|
// Honor extended resource if the pod requests.
|
||||||
@ -368,7 +356,7 @@ func TestLeastAllocatedScoringStrategy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
existingPods: nil,
|
existingPods: nil,
|
||||||
expectedScores: []framework.NodeScore{{Name: "node1", Score: 50}, {Name: "node2", Score: 60}},
|
expectedScores: []framework.NodeScore{{Name: "node1", Score: 50}, {Name: "node2", Score: 60}},
|
||||||
resources: extendedResourceLeastAllocatedSet,
|
resources: extendedResourceSet,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,17 +32,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMostAllocatedScoringStrategy(t *testing.T) {
|
func TestMostAllocatedScoringStrategy(t *testing.T) {
|
||||||
defaultResources := []config.ResourceSpec{
|
|
||||||
{Name: string(v1.ResourceCPU), Weight: 1},
|
|
||||||
{Name: string(v1.ResourceMemory), Weight: 1},
|
|
||||||
}
|
|
||||||
extendedRes := "abc.com/xyz"
|
|
||||||
extendedResourceLeastAllocatedSet := []config.ResourceSpec{
|
|
||||||
{Name: string(v1.ResourceCPU), Weight: 1},
|
|
||||||
{Name: string(v1.ResourceMemory), Weight: 1},
|
|
||||||
{Name: extendedRes, Weight: 1},
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
requestedPod *v1.Pod
|
requestedPod *v1.Pod
|
||||||
@ -75,7 +64,7 @@ func TestMostAllocatedScoringStrategy(t *testing.T) {
|
|||||||
// Node1 scores on 0-MaxNodeScore scale
|
// Node1 scores on 0-MaxNodeScore scale
|
||||||
// CPU Score: (3000 * MaxNodeScore) / 4000 = 75
|
// CPU Score: (3000 * MaxNodeScore) / 4000 = 75
|
||||||
// Memory Score: (5000 * MaxNodeScore) / 10000 = 50
|
// Memory Score: (5000 * MaxNodeScore) / 10000 = 50
|
||||||
// Node1 Score: (75 + 50) / 2 = 6
|
// Node1 Score: (75 + 50) / 2 = 62
|
||||||
// Node2 scores on 0-MaxNodeScore scale
|
// Node2 scores on 0-MaxNodeScore scale
|
||||||
// CPU Score: (3000 * MaxNodeScore) / 6000 = 50
|
// CPU Score: (3000 * MaxNodeScore) / 6000 = 50
|
||||||
// Memory Score: (5000 * MaxNodeScore) / 10000 = 50
|
// Memory Score: (5000 * MaxNodeScore) / 10000 = 50
|
||||||
@ -301,7 +290,7 @@ func TestMostAllocatedScoringStrategy(t *testing.T) {
|
|||||||
st.MakeNode().Name("node1").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000"}).Obj(),
|
st.MakeNode().Name("node1").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000"}).Obj(),
|
||||||
st.MakeNode().Name("node2").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000", v1.ResourceName(extendedRes): "4"}).Obj(),
|
st.MakeNode().Name("node2").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000", v1.ResourceName(extendedRes): "4"}).Obj(),
|
||||||
},
|
},
|
||||||
resources: extendedResourceLeastAllocatedSet,
|
resources: extendedResourceSet,
|
||||||
existingPods: nil,
|
existingPods: nil,
|
||||||
expectedScores: []framework.NodeScore{{Name: "node1", Score: 50}, {Name: "node2", Score: 50}},
|
expectedScores: []framework.NodeScore{{Name: "node1", Score: 50}, {Name: "node2", Score: 50}},
|
||||||
},
|
},
|
||||||
@ -322,7 +311,7 @@ func TestMostAllocatedScoringStrategy(t *testing.T) {
|
|||||||
st.MakeNode().Name("node1").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000", v1.ResourceName(extendedRes): "4"}).Obj(),
|
st.MakeNode().Name("node1").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000", v1.ResourceName(extendedRes): "4"}).Obj(),
|
||||||
st.MakeNode().Name("node2").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000", v1.ResourceName(extendedRes): "10"}).Obj(),
|
st.MakeNode().Name("node2").Capacity(map[v1.ResourceName]string{"cpu": "6000", "memory": "10000", v1.ResourceName(extendedRes): "10"}).Obj(),
|
||||||
},
|
},
|
||||||
resources: extendedResourceLeastAllocatedSet,
|
resources: extendedResourceSet,
|
||||||
existingPods: nil,
|
existingPods: nil,
|
||||||
expectedScores: []framework.NodeScore{{Name: "node1", Score: 50}, {Name: "node2", Score: 40}},
|
expectedScores: []framework.NodeScore{{Name: "node1", Score: 50}, {Name: "node2", Score: 40}},
|
||||||
},
|
},
|
||||||
|
@ -36,11 +36,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRequestedToCapacityRatioScoringStrategy(t *testing.T) {
|
func TestRequestedToCapacityRatioScoringStrategy(t *testing.T) {
|
||||||
defaultResources := []config.ResourceSpec{
|
|
||||||
{Name: string(v1.ResourceCPU), Weight: 1},
|
|
||||||
{Name: string(v1.ResourceMemory), Weight: 1},
|
|
||||||
}
|
|
||||||
|
|
||||||
shape := []config.UtilizationShapePoint{
|
shape := []config.UtilizationShapePoint{
|
||||||
{Utilization: 0, Score: 10},
|
{Utilization: 0, Score: 10},
|
||||||
{Utilization: 100, Score: 0},
|
{Utilization: 100, Score: 0},
|
||||||
@ -208,7 +203,7 @@ func TestBrokenLinearFunction(t *testing.T) {
|
|||||||
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||||
function := helper.BuildBrokenLinearFunction(test.points)
|
function := helper.BuildBrokenLinearFunction(test.points)
|
||||||
for _, assertion := range test.assertions {
|
for _, assertion := range test.assertions {
|
||||||
assert.InDelta(t, assertion.expected, function(assertion.p), 0.1, "points=%v, p=%f", test.points, assertion.p)
|
assert.InDelta(t, assertion.expected, function(assertion.p), 0.1, "points=%v, p=%d", test.points, assertion.p)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,21 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ignoreBadValueDetail = cmpopts.IgnoreFields(field.Error{}, "BadValue", "Detail")
|
ignoreBadValueDetail = cmpopts.IgnoreFields(field.Error{}, "BadValue", "Detail")
|
||||||
|
defaultResources = []config.ResourceSpec{
|
||||||
|
{Name: string(v1.ResourceCPU), Weight: 1},
|
||||||
|
{Name: string(v1.ResourceMemory), Weight: 1},
|
||||||
|
}
|
||||||
|
extendedRes = "abc.com/xyz"
|
||||||
|
extendedResourceSet = []config.ResourceSpec{
|
||||||
|
{Name: string(v1.ResourceCPU), Weight: 1},
|
||||||
|
{Name: string(v1.ResourceMemory), Weight: 1},
|
||||||
|
{Name: extendedRes, Weight: 1},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeNode(node string, milliCPU, memory int64, extendedResource map[string]int64) *v1.Node {
|
func makeNode(node string, milliCPU, memory int64, extendedResource map[string]int64) *v1.Node {
|
||||||
|
Loading…
Reference in New Issue
Block a user