Add test
This commit is contained in:
parent
a7057f8df0
commit
fb895056c6
@ -388,7 +388,7 @@ func (pl *InterPodAffinity) RemovePod(ctx context.Context, cycleState *framework
|
|||||||
func getPreFilterState(cycleState *framework.CycleState) (*preFilterState, error) {
|
func getPreFilterState(cycleState *framework.CycleState) (*preFilterState, error) {
|
||||||
c, err := cycleState.Read(preFilterStateKey)
|
c, err := cycleState.Read(preFilterStateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// The preFilterState wasn't pre-computed in prefilter.
|
// preFilterState doesn't exist, likely PreFilter wasn't invoked.
|
||||||
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1634,6 +1634,20 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPreFilterDisabled(t *testing.T) {
|
||||||
|
pod := &v1.Pod{}
|
||||||
|
nodeInfo := nodeinfo.NewNodeInfo()
|
||||||
|
node := v1.Node{}
|
||||||
|
nodeInfo.SetNode(&node)
|
||||||
|
p := &InterPodAffinity{}
|
||||||
|
cycleState := framework.NewCycleState()
|
||||||
|
gotStatus := p.Filter(context.Background(), cycleState, pod, nodeInfo)
|
||||||
|
wantStatus := framework.NewStatus(framework.Error, `error reading "PreFilterInterPodAffinity" from cycleState: not found`)
|
||||||
|
if !reflect.DeepEqual(gotStatus, wantStatus) {
|
||||||
|
t.Errorf("status does not match: %v, want: %v", gotStatus, wantStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPreFilterStateAddRemovePod(t *testing.T) {
|
func TestPreFilterStateAddRemovePod(t *testing.T) {
|
||||||
var label1 = map[string]string{
|
var label1 = map[string]string{
|
||||||
"region": "r1",
|
"region": "r1",
|
||||||
|
@ -86,7 +86,7 @@ func (pl *NodePorts) PreFilterExtensions() framework.PreFilterExtensions {
|
|||||||
func getPreFilterState(cycleState *framework.CycleState) (preFilterState, error) {
|
func getPreFilterState(cycleState *framework.CycleState) (preFilterState, error) {
|
||||||
c, err := cycleState.Read(preFilterStateKey)
|
c, err := cycleState.Read(preFilterStateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// preFilterState state doesn't exist.
|
// preFilterState doesn't exist, likely PreFilter wasn't invoked.
|
||||||
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +163,20 @@ func TestNodePorts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPreFilterDisabled(t *testing.T) {
|
||||||
|
pod := &v1.Pod{}
|
||||||
|
nodeInfo := schedulernodeinfo.NewNodeInfo()
|
||||||
|
node := v1.Node{}
|
||||||
|
nodeInfo.SetNode(&node)
|
||||||
|
p, _ := New(nil, nil)
|
||||||
|
cycleState := framework.NewCycleState()
|
||||||
|
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), cycleState, pod, nodeInfo)
|
||||||
|
wantStatus := framework.NewStatus(framework.Error, `error reading "PreFilterNodePorts" from cycleState: not found`)
|
||||||
|
if !reflect.DeepEqual(gotStatus, wantStatus) {
|
||||||
|
t.Errorf("status does not match: %v, want: %v", gotStatus, wantStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetContainerPorts(t *testing.T) {
|
func TestGetContainerPorts(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
pod1 *v1.Pod
|
pod1 *v1.Pod
|
||||||
|
@ -129,7 +129,7 @@ func (f *Fit) PreFilterExtensions() framework.PreFilterExtensions {
|
|||||||
func getPreFilterState(cycleState *framework.CycleState) (*preFilterState, error) {
|
func getPreFilterState(cycleState *framework.CycleState) (*preFilterState, error) {
|
||||||
c, err := cycleState.Read(preFilterStateKey)
|
c, err := cycleState.Read(preFilterStateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// The preFilterState doesn't exist.
|
// preFilterState doesn't exist, likely PreFilter wasn't invoked.
|
||||||
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,6 +398,20 @@ func TestEnoughRequests(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPreFilterDisabled(t *testing.T) {
|
||||||
|
pod := &v1.Pod{}
|
||||||
|
nodeInfo := schedulernodeinfo.NewNodeInfo()
|
||||||
|
node := v1.Node{}
|
||||||
|
nodeInfo.SetNode(&node)
|
||||||
|
p, _ := NewFit(nil, nil)
|
||||||
|
cycleState := framework.NewCycleState()
|
||||||
|
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), cycleState, pod, nodeInfo)
|
||||||
|
wantStatus := framework.NewStatus(framework.Error, `error reading "PreFilterNodeResourcesFit" from cycleState: not found`)
|
||||||
|
if !reflect.DeepEqual(gotStatus, wantStatus) {
|
||||||
|
t.Errorf("status does not match: %v, want: %v", gotStatus, wantStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestNotEnoughRequests(t *testing.T) {
|
func TestNotEnoughRequests(t *testing.T) {
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodOverhead, true)()
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodOverhead, true)()
|
||||||
notEnoughPodsTests := []struct {
|
notEnoughPodsTests := []struct {
|
||||||
|
@ -35,6 +35,7 @@ go_test(
|
|||||||
deps = [
|
deps = [
|
||||||
"//pkg/scheduler/framework/v1alpha1:go_default_library",
|
"//pkg/scheduler/framework/v1alpha1:go_default_library",
|
||||||
"//pkg/scheduler/internal/cache:go_default_library",
|
"//pkg/scheduler/internal/cache:go_default_library",
|
||||||
|
"//pkg/scheduler/nodeinfo:go_default_library",
|
||||||
"//pkg/scheduler/testing:go_default_library",
|
"//pkg/scheduler/testing:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
@ -194,7 +194,7 @@ func (pl *PodTopologySpread) RemovePod(ctx context.Context, cycleState *framewor
|
|||||||
func getPreFilterState(cycleState *framework.CycleState) (*preFilterState, error) {
|
func getPreFilterState(cycleState *framework.CycleState) (*preFilterState, error) {
|
||||||
c, err := cycleState.Read(preFilterStateKey)
|
c, err := cycleState.Read(preFilterStateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// The preFilterState wasn't pre-computed in prefilter.
|
// preFilterState doesn't exist, likely PreFilter wasn't invoked.
|
||||||
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||||
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
st "k8s.io/kubernetes/pkg/scheduler/testing"
|
st "k8s.io/kubernetes/pkg/scheduler/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1464,3 +1465,17 @@ func TestMultipleConstraints(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPreFilterDisabled(t *testing.T) {
|
||||||
|
pod := &v1.Pod{}
|
||||||
|
nodeInfo := schedulernodeinfo.NewNodeInfo()
|
||||||
|
node := v1.Node{}
|
||||||
|
nodeInfo.SetNode(&node)
|
||||||
|
p := &PodTopologySpread{}
|
||||||
|
cycleState := framework.NewCycleState()
|
||||||
|
gotStatus := p.Filter(context.Background(), cycleState, pod, nodeInfo)
|
||||||
|
wantStatus := framework.NewStatus(framework.Error, `error reading "PreFilterPodTopologySpread" from cycleState: not found`)
|
||||||
|
if !reflect.DeepEqual(gotStatus, wantStatus) {
|
||||||
|
t.Errorf("status does not match: %v, want: %v", gotStatus, wantStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -190,7 +190,7 @@ func (pl *ServiceAffinity) RemovePod(ctx context.Context, cycleState *framework.
|
|||||||
func getPreFilterState(cycleState *framework.CycleState) (*preFilterState, error) {
|
func getPreFilterState(cycleState *framework.CycleState) (*preFilterState, error) {
|
||||||
c, err := cycleState.Read(preFilterStateKey)
|
c, err := cycleState.Read(preFilterStateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// The metadata wasn't pre-computed in prefilter.
|
// preFilterState doesn't exist, likely PreFilter wasn't invoked.
|
||||||
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,3 +599,21 @@ func mustGetNodeInfo(t *testing.T, snapshot *cache.Snapshot, name string) *nodei
|
|||||||
}
|
}
|
||||||
return nodeInfo
|
return nodeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPreFilterDisabled(t *testing.T) {
|
||||||
|
pod := &v1.Pod{}
|
||||||
|
nodeInfo := nodeinfo.NewNodeInfo()
|
||||||
|
node := v1.Node{}
|
||||||
|
nodeInfo.SetNode(&node)
|
||||||
|
p := &ServiceAffinity{
|
||||||
|
args: Args{
|
||||||
|
AffinityLabels: []string{"region"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cycleState := framework.NewCycleState()
|
||||||
|
gotStatus := p.Filter(context.Background(), cycleState, pod, nodeInfo)
|
||||||
|
wantStatus := framework.NewStatus(framework.Error, `error reading "PreFilterServiceAffinity" from cycleState: not found`)
|
||||||
|
if !reflect.DeepEqual(gotStatus, wantStatus) {
|
||||||
|
t.Errorf("status does not match: %v, want: %v", gotStatus, wantStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user