mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 03:38:15 +00:00
add arg for noderesourcesfit plugin to support ignore a group of extended resources
This commit is contained in:
@@ -20,13 +20,13 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
)
|
||||
|
||||
@@ -367,6 +367,31 @@ func TestEnoughRequests(t *testing.T) {
|
||||
wantStatus: framework.NewStatus(framework.Unschedulable, getErrReason(v1.ResourceMemory)),
|
||||
wantInsufficientResources: []InsufficientResource{{v1.ResourceMemory, getErrReason(v1.ResourceMemory), 16, 5, 20}},
|
||||
},
|
||||
{
|
||||
pod: newResourcePod(
|
||||
framework.Resource{
|
||||
MilliCPU: 1,
|
||||
Memory: 1,
|
||||
ScalarResources: map[v1.ResourceName]int64{
|
||||
extendedResourceB: 1,
|
||||
kubernetesIOResourceA: 1,
|
||||
}}),
|
||||
nodeInfo: framework.NewNodeInfo(newResourcePod(framework.Resource{MilliCPU: 0, Memory: 0})),
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{"example.com"},
|
||||
},
|
||||
name: "skip checking ignored extended resource via resource groups",
|
||||
wantStatus: framework.NewStatus(framework.Unschedulable, fmt.Sprintf("Insufficient %v", kubernetesIOResourceA)),
|
||||
wantInsufficientResources: []InsufficientResource{
|
||||
{
|
||||
ResourceName: kubernetesIOResourceA,
|
||||
Reason: fmt.Sprintf("Insufficient %v", kubernetesIOResourceA),
|
||||
Requested: 1,
|
||||
Used: 0,
|
||||
Capacity: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range enoughPodsTests {
|
||||
@@ -389,9 +414,9 @@ func TestEnoughRequests(t *testing.T) {
|
||||
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
|
||||
}
|
||||
|
||||
gotInsufficientResources := Fits(test.pod, test.nodeInfo, p.(*Fit).ignoredResources)
|
||||
gotInsufficientResources := fitsRequest(computePodResourceRequest(test.pod), test.nodeInfo, p.(*Fit).ignoredResources, p.(*Fit).ignoredResourceGroups)
|
||||
if !reflect.DeepEqual(gotInsufficientResources, test.wantInsufficientResources) {
|
||||
t.Errorf("insufficient resources do not match: %v, want: %v", gotInsufficientResources, test.wantInsufficientResources)
|
||||
t.Errorf("insufficient resources do not match: %+v, want: %v", gotInsufficientResources, test.wantInsufficientResources)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -529,3 +554,72 @@ func TestStorageRequests(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestValidateFitArgs(t *testing.T) {
|
||||
argsTest := []struct {
|
||||
name string
|
||||
args config.NodeResourcesFitArgs
|
||||
expect string
|
||||
}{
|
||||
{
|
||||
name: "IgnoredResources: too long value",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResources: []string{fmt.Sprintf("longvalue%s", strings.Repeat("a", 64))},
|
||||
},
|
||||
expect: "name part must be no more than 63 characters",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResources: name is empty",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResources: []string{"example.com/"},
|
||||
},
|
||||
expect: "name part must be non-empty",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResources: name has too many slash",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResources: []string{"example.com/aaa/bbb"},
|
||||
},
|
||||
expect: "a qualified name must consist of alphanumeric characters",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResources: valid args",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResources: []string{"example.com"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "IgnoredResourceGroups: valid args ",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{"example.com"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "IgnoredResourceGroups: illegal args",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{"example.com/"},
|
||||
},
|
||||
expect: "name part must be non-empty",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResourceGroups: name is too long",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{strings.Repeat("a", 64)},
|
||||
},
|
||||
expect: "name part must be no more than 63 characters",
|
||||
},
|
||||
{
|
||||
name: "IgnoredResourceGroups: name cannot be contain slash",
|
||||
args: config.NodeResourcesFitArgs{
|
||||
IgnoredResourceGroups: []string{"example.com/aa"},
|
||||
},
|
||||
expect: "resource group name can't contain '/'",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range argsTest {
|
||||
if err := validateFitArgs(test.args); err != nil && !strings.Contains(err.Error(), test.expect) {
|
||||
t.Errorf("case[%v]: error details do not include %v", test.name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user