mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #63666 from xchapter7x/pkg-scheduler-factory
Automatic merge from submit-queue (batch tested with PRs 58487, 63666). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. use subtest for table units (pkg/scheduler/factory) **What this PR does / why we need it**: Update scheduler's unit table tests to use subtest **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: **Special notes for your reviewer**: breaks up PR: https://github.com/kubernetes/kubernetes/pull/63281 /ref #63267 **Release note**: ```release-note This PR will leverage subtests on the existing table tests for the scheduler units. Some refactoring of error/status messages and functions to align with new approach. ```
This commit is contained in:
commit
357decc9db
@ -27,27 +27,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCompareNodes(t *testing.T) {
|
func TestCompareNodes(t *testing.T) {
|
||||||
compare := compareStrategy{}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
actual []string
|
actual []string
|
||||||
cached []string
|
cached []string
|
||||||
missing []string
|
missing []string
|
||||||
redundant []string
|
redundant []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "redundant cached value",
|
||||||
actual: []string{"foo", "bar"},
|
actual: []string{"foo", "bar"},
|
||||||
cached: []string{"bar", "foo", "foobar"},
|
cached: []string{"bar", "foo", "foobar"},
|
||||||
missing: []string{},
|
missing: []string{},
|
||||||
redundant: []string{"foobar"},
|
redundant: []string{"foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "missing cached value",
|
||||||
actual: []string{"foo", "bar", "foobar"},
|
actual: []string{"foo", "bar", "foobar"},
|
||||||
cached: []string{"bar", "foo"},
|
cached: []string{"bar", "foo"},
|
||||||
missing: []string{"foobar"},
|
missing: []string{"foobar"},
|
||||||
redundant: []string{},
|
redundant: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "proper cache set",
|
||||||
actual: []string{"foo", "bar", "foobar"},
|
actual: []string{"foo", "bar", "foobar"},
|
||||||
cached: []string{"bar", "foobar", "foo"},
|
cached: []string{"bar", "foobar", "foo"},
|
||||||
missing: []string{},
|
missing: []string{},
|
||||||
@ -56,34 +58,40 @@ func TestCompareNodes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
nodes := []*v1.Node{}
|
t.Run(test.name, func(t *testing.T) {
|
||||||
for _, nodeName := range test.actual {
|
testCompareNodes(test.actual, test.cached, test.missing, test.redundant, t)
|
||||||
node := &v1.Node{}
|
})
|
||||||
node.Name = nodeName
|
}
|
||||||
nodes = append(nodes, node)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
nodeInfo := make(map[string]*schedulercache.NodeInfo)
|
func testCompareNodes(actual, cached, missing, redundant []string, t *testing.T) {
|
||||||
for _, nodeName := range test.cached {
|
compare := compareStrategy{}
|
||||||
nodeInfo[nodeName] = &schedulercache.NodeInfo{}
|
nodes := []*v1.Node{}
|
||||||
}
|
for _, nodeName := range actual {
|
||||||
|
node := &v1.Node{}
|
||||||
|
node.Name = nodeName
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
}
|
||||||
|
|
||||||
m, r := compare.CompareNodes(nodes, nodeInfo)
|
nodeInfo := make(map[string]*schedulercache.NodeInfo)
|
||||||
|
for _, nodeName := range cached {
|
||||||
|
nodeInfo[nodeName] = &schedulercache.NodeInfo{}
|
||||||
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(m, test.missing) {
|
m, r := compare.CompareNodes(nodes, nodeInfo)
|
||||||
t.Errorf("missing expected to be %s; got %s", test.missing, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(r, test.redundant) {
|
if !reflect.DeepEqual(m, missing) {
|
||||||
t.Errorf("redundant expected to be %s; got %s", test.redundant, r)
|
t.Errorf("missing expected to be %s; got %s", missing, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(r, redundant) {
|
||||||
|
t.Errorf("redundant expected to be %s; got %s", redundant, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestComparePods(t *testing.T) {
|
func TestComparePods(t *testing.T) {
|
||||||
compare := compareStrategy{}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
actual []string
|
actual []string
|
||||||
cached []string
|
cached []string
|
||||||
queued []string
|
queued []string
|
||||||
@ -91,6 +99,7 @@ func TestComparePods(t *testing.T) {
|
|||||||
redundant []string
|
redundant []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "redundant cached value",
|
||||||
actual: []string{"foo", "bar"},
|
actual: []string{"foo", "bar"},
|
||||||
cached: []string{"bar", "foo", "foobar"},
|
cached: []string{"bar", "foo", "foobar"},
|
||||||
queued: []string{},
|
queued: []string{},
|
||||||
@ -98,6 +107,7 @@ func TestComparePods(t *testing.T) {
|
|||||||
redundant: []string{"foobar"},
|
redundant: []string{"foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "redundant and queued values",
|
||||||
actual: []string{"foo", "bar"},
|
actual: []string{"foo", "bar"},
|
||||||
cached: []string{"foo", "foobar"},
|
cached: []string{"foo", "foobar"},
|
||||||
queued: []string{"bar"},
|
queued: []string{"bar"},
|
||||||
@ -105,6 +115,7 @@ func TestComparePods(t *testing.T) {
|
|||||||
redundant: []string{"foobar"},
|
redundant: []string{"foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "missing cached value",
|
||||||
actual: []string{"foo", "bar", "foobar"},
|
actual: []string{"foo", "bar", "foobar"},
|
||||||
cached: []string{"bar", "foo"},
|
cached: []string{"bar", "foo"},
|
||||||
queued: []string{},
|
queued: []string{},
|
||||||
@ -112,6 +123,7 @@ func TestComparePods(t *testing.T) {
|
|||||||
redundant: []string{},
|
redundant: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "missing and queued values",
|
||||||
actual: []string{"foo", "bar", "foobar"},
|
actual: []string{"foo", "bar", "foobar"},
|
||||||
cached: []string{"foo"},
|
cached: []string{"foo"},
|
||||||
queued: []string{"bar"},
|
queued: []string{"bar"},
|
||||||
@ -119,6 +131,7 @@ func TestComparePods(t *testing.T) {
|
|||||||
redundant: []string{},
|
redundant: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "correct cache set",
|
||||||
actual: []string{"foo", "bar", "foobar"},
|
actual: []string{"foo", "bar", "foobar"},
|
||||||
cached: []string{"bar", "foobar", "foo"},
|
cached: []string{"bar", "foobar", "foo"},
|
||||||
queued: []string{},
|
queued: []string{},
|
||||||
@ -126,6 +139,7 @@ func TestComparePods(t *testing.T) {
|
|||||||
redundant: []string{},
|
redundant: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "queued cache value",
|
||||||
actual: []string{"foo", "bar", "foobar"},
|
actual: []string{"foo", "bar", "foobar"},
|
||||||
cached: []string{"foobar", "foo"},
|
cached: []string{"foobar", "foo"},
|
||||||
queued: []string{"bar"},
|
queued: []string{"bar"},
|
||||||
@ -135,64 +149,73 @@ func TestComparePods(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
pods := []*v1.Pod{}
|
t.Run(test.name, func(t *testing.T) {
|
||||||
for _, uid := range test.actual {
|
testComparePods(test.actual, test.cached, test.queued, test.missing, test.redundant, t)
|
||||||
pod := &v1.Pod{}
|
})
|
||||||
pod.UID = types.UID(uid)
|
}
|
||||||
pods = append(pods, pod)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
queuedPods := []*v1.Pod{}
|
func testComparePods(actual, cached, queued, missing, redundant []string, t *testing.T) {
|
||||||
for _, uid := range test.queued {
|
compare := compareStrategy{}
|
||||||
pod := &v1.Pod{}
|
pods := []*v1.Pod{}
|
||||||
pod.UID = types.UID(uid)
|
for _, uid := range actual {
|
||||||
queuedPods = append(queuedPods, pod)
|
pod := &v1.Pod{}
|
||||||
}
|
pod.UID = types.UID(uid)
|
||||||
|
pods = append(pods, pod)
|
||||||
|
}
|
||||||
|
|
||||||
nodeInfo := make(map[string]*schedulercache.NodeInfo)
|
queuedPods := []*v1.Pod{}
|
||||||
for _, uid := range test.cached {
|
for _, uid := range queued {
|
||||||
pod := &v1.Pod{}
|
pod := &v1.Pod{}
|
||||||
pod.UID = types.UID(uid)
|
pod.UID = types.UID(uid)
|
||||||
pod.Namespace = "ns"
|
queuedPods = append(queuedPods, pod)
|
||||||
pod.Name = uid
|
}
|
||||||
|
|
||||||
nodeInfo[uid] = schedulercache.NewNodeInfo(pod)
|
nodeInfo := make(map[string]*schedulercache.NodeInfo)
|
||||||
}
|
for _, uid := range cached {
|
||||||
|
pod := &v1.Pod{}
|
||||||
|
pod.UID = types.UID(uid)
|
||||||
|
pod.Namespace = "ns"
|
||||||
|
pod.Name = uid
|
||||||
|
|
||||||
m, r := compare.ComparePods(pods, queuedPods, nodeInfo)
|
nodeInfo[uid] = schedulercache.NewNodeInfo(pod)
|
||||||
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(m, test.missing) {
|
m, r := compare.ComparePods(pods, queuedPods, nodeInfo)
|
||||||
t.Errorf("missing expected to be %s; got %s", test.missing, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(r, test.redundant) {
|
if !reflect.DeepEqual(m, missing) {
|
||||||
t.Errorf("redundant expected to be %s; got %s", test.redundant, r)
|
t.Errorf("missing expected to be %s; got %s", missing, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(r, redundant) {
|
||||||
|
t.Errorf("redundant expected to be %s; got %s", redundant, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestComparePdbs(t *testing.T) {
|
func TestComparePdbs(t *testing.T) {
|
||||||
compare := compareStrategy{}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
actual []string
|
actual []string
|
||||||
cached []string
|
cached []string
|
||||||
missing []string
|
missing []string
|
||||||
redundant []string
|
redundant []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "redundant cache value",
|
||||||
actual: []string{"foo", "bar"},
|
actual: []string{"foo", "bar"},
|
||||||
cached: []string{"bar", "foo", "foobar"},
|
cached: []string{"bar", "foo", "foobar"},
|
||||||
missing: []string{},
|
missing: []string{},
|
||||||
redundant: []string{"foobar"},
|
redundant: []string{"foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "missing cache value",
|
||||||
actual: []string{"foo", "bar", "foobar"},
|
actual: []string{"foo", "bar", "foobar"},
|
||||||
cached: []string{"bar", "foo"},
|
cached: []string{"bar", "foo"},
|
||||||
missing: []string{"foobar"},
|
missing: []string{"foobar"},
|
||||||
redundant: []string{},
|
redundant: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "correct cache",
|
||||||
actual: []string{"foo", "bar", "foobar"},
|
actual: []string{"foo", "bar", "foobar"},
|
||||||
cached: []string{"bar", "foobar", "foo"},
|
cached: []string{"bar", "foobar", "foo"},
|
||||||
missing: []string{},
|
missing: []string{},
|
||||||
@ -201,28 +224,35 @@ func TestComparePdbs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
pdbs := []*policy.PodDisruptionBudget{}
|
t.Run(test.name, func(t *testing.T) {
|
||||||
for _, uid := range test.actual {
|
testComparePdbs(test.actual, test.cached, test.missing, test.redundant, t)
|
||||||
pdb := &policy.PodDisruptionBudget{}
|
})
|
||||||
pdb.UID = types.UID(uid)
|
}
|
||||||
pdbs = append(pdbs, pdb)
|
}
|
||||||
}
|
|
||||||
|
func testComparePdbs(actual, cached, missing, redundant []string, t *testing.T) {
|
||||||
cache := make(map[string]*policy.PodDisruptionBudget)
|
compare := compareStrategy{}
|
||||||
for _, uid := range test.cached {
|
pdbs := []*policy.PodDisruptionBudget{}
|
||||||
pdb := &policy.PodDisruptionBudget{}
|
for _, uid := range actual {
|
||||||
pdb.UID = types.UID(uid)
|
pdb := &policy.PodDisruptionBudget{}
|
||||||
cache[uid] = pdb
|
pdb.UID = types.UID(uid)
|
||||||
}
|
pdbs = append(pdbs, pdb)
|
||||||
|
}
|
||||||
m, r := compare.ComparePdbs(pdbs, cache)
|
|
||||||
|
cache := make(map[string]*policy.PodDisruptionBudget)
|
||||||
if !reflect.DeepEqual(m, test.missing) {
|
for _, uid := range cached {
|
||||||
t.Errorf("missing expected to be %s; got %s", test.missing, m)
|
pdb := &policy.PodDisruptionBudget{}
|
||||||
}
|
pdb.UID = types.UID(uid)
|
||||||
|
cache[uid] = pdb
|
||||||
if !reflect.DeepEqual(r, test.redundant) {
|
}
|
||||||
t.Errorf("redundant expected to be %s; got %s", test.redundant, r)
|
|
||||||
}
|
m, r := compare.ComparePdbs(pdbs, cache)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(m, missing) {
|
||||||
|
t.Errorf("missing expected to be %s; got %s", missing, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(r, redundant) {
|
||||||
|
t.Errorf("redundant expected to be %s; got %s", redundant, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,53 +331,65 @@ func TestNodeEnumerator(t *testing.T) {
|
|||||||
t.Fatalf("expected %v, got %v", e, a)
|
t.Fatalf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
for i := range testList.Items {
|
for i := range testList.Items {
|
||||||
gotObj := me.Get(i)
|
t.Run(fmt.Sprintf("node enumerator/%v", i), func(t *testing.T) {
|
||||||
if e, a := testList.Items[i].Name, gotObj.(*v1.Node).Name; e != a {
|
gotObj := me.Get(i)
|
||||||
t.Errorf("Expected %v, got %v", e, a)
|
if e, a := testList.Items[i].Name, gotObj.(*v1.Node).Name; e != a {
|
||||||
}
|
t.Errorf("Expected %v, got %v", e, a)
|
||||||
if e, a := &testList.Items[i], gotObj; !reflect.DeepEqual(e, a) {
|
}
|
||||||
t.Errorf("Expected %#v, got %v#", e, a)
|
if e, a := &testList.Items[i], gotObj; !reflect.DeepEqual(e, a) {
|
||||||
}
|
t.Errorf("Expected %#v, got %v#", e, a)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBind(t *testing.T) {
|
func TestBind(t *testing.T) {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
|
name string
|
||||||
binding *v1.Binding
|
binding *v1.Binding
|
||||||
}{
|
}{
|
||||||
{binding: &v1.Binding{
|
{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
name: "binding can bind and validate request",
|
||||||
Namespace: metav1.NamespaceDefault,
|
binding: &v1.Binding{
|
||||||
Name: "foo",
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: metav1.NamespaceDefault,
|
||||||
|
Name: "foo",
|
||||||
|
},
|
||||||
|
Target: v1.ObjectReference{
|
||||||
|
Name: "foohost.kubernetes.mydomain.com",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Target: v1.ObjectReference{
|
},
|
||||||
Name: "foohost.kubernetes.mydomain.com",
|
|
||||||
},
|
|
||||||
}},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range table {
|
for _, test := range table {
|
||||||
handler := utiltesting.FakeHandler{
|
t.Run(test.name, func(t *testing.T) {
|
||||||
StatusCode: 200,
|
testBind(test.binding, t)
|
||||||
ResponseBody: "",
|
})
|
||||||
T: t,
|
|
||||||
}
|
|
||||||
server := httptest.NewServer(&handler)
|
|
||||||
defer server.Close()
|
|
||||||
client := clientset.NewForConfigOrDie(&restclient.Config{Host: server.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
|
|
||||||
b := binder{client}
|
|
||||||
|
|
||||||
if err := b.Bind(item.binding); err != nil {
|
|
||||||
t.Errorf("Unexpected error: %v", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
expectedBody := runtime.EncodeOrDie(schedulertesting.Test.Codec(), item.binding)
|
|
||||||
handler.ValidateRequest(t,
|
|
||||||
schedulertesting.Test.SubResourcePath(string(v1.ResourcePods), metav1.NamespaceDefault, "foo", "binding"),
|
|
||||||
"POST", &expectedBody)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testBind(binding *v1.Binding, t *testing.T) {
|
||||||
|
handler := utiltesting.FakeHandler{
|
||||||
|
StatusCode: 200,
|
||||||
|
ResponseBody: "",
|
||||||
|
T: t,
|
||||||
|
}
|
||||||
|
server := httptest.NewServer(&handler)
|
||||||
|
defer server.Close()
|
||||||
|
client := clientset.NewForConfigOrDie(&restclient.Config{Host: server.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
|
||||||
|
b := binder{client}
|
||||||
|
|
||||||
|
if err := b.Bind(binding); err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
expectedBody := runtime.EncodeOrDie(schedulertesting.Test.Codec(), binding)
|
||||||
|
handler.ValidateRequest(t,
|
||||||
|
schedulertesting.Test.SubResourcePath(string(v1.ResourcePods), metav1.NamespaceDefault, "foo", "binding"),
|
||||||
|
"POST", &expectedBody)
|
||||||
|
}
|
||||||
|
|
||||||
func TestInvalidHardPodAffinitySymmetricWeight(t *testing.T) {
|
func TestInvalidHardPodAffinitySymmetricWeight(t *testing.T) {
|
||||||
handler := utiltesting.FakeHandler{
|
handler := utiltesting.FakeHandler{
|
||||||
StatusCode: 500,
|
StatusCode: 500,
|
||||||
@ -406,38 +418,44 @@ func TestInvalidFactoryArgs(t *testing.T) {
|
|||||||
client := clientset.NewForConfigOrDie(&restclient.Config{Host: server.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
|
client := clientset.NewForConfigOrDie(&restclient.Config{Host: server.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
name string
|
||||||
hardPodAffinitySymmetricWeight int32
|
hardPodAffinitySymmetricWeight int32
|
||||||
expectErr string
|
expectErr string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "symmetric weight below range",
|
||||||
hardPodAffinitySymmetricWeight: -1,
|
hardPodAffinitySymmetricWeight: -1,
|
||||||
expectErr: "invalid hardPodAffinitySymmetricWeight: -1, must be in the range 0-100",
|
expectErr: "invalid hardPodAffinitySymmetricWeight: -1, must be in the range 0-100",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "symmetric weight above range",
|
||||||
hardPodAffinitySymmetricWeight: 101,
|
hardPodAffinitySymmetricWeight: 101,
|
||||||
expectErr: "invalid hardPodAffinitySymmetricWeight: 101, must be in the range 0-100",
|
expectErr: "invalid hardPodAffinitySymmetricWeight: 101, must be in the range 0-100",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
factory := newConfigFactory(client, test.hardPodAffinitySymmetricWeight)
|
t.Run(test.name, func(t *testing.T) {
|
||||||
_, err := factory.Create()
|
factory := newConfigFactory(client, test.hardPodAffinitySymmetricWeight)
|
||||||
if err == nil {
|
_, err := factory.Create()
|
||||||
t.Errorf("expected err: %s, got nothing", test.expectErr)
|
if err == nil {
|
||||||
}
|
t.Errorf("expected err: %s, got nothing", test.expectErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSkipPodUpdate(t *testing.T) {
|
func TestSkipPodUpdate(t *testing.T) {
|
||||||
for _, test := range []struct {
|
table := []struct {
|
||||||
pod *v1.Pod
|
pod *v1.Pod
|
||||||
isAssumedPodFunc func(*v1.Pod) bool
|
isAssumedPodFunc func(*v1.Pod) bool
|
||||||
getPodFunc func(*v1.Pod) *v1.Pod
|
getPodFunc func(*v1.Pod) *v1.Pod
|
||||||
expected bool
|
expected bool
|
||||||
|
name string
|
||||||
}{
|
}{
|
||||||
// Non-assumed pod should not be skipped.
|
|
||||||
{
|
{
|
||||||
|
name: "Non-assumed pod",
|
||||||
pod: &v1.Pod{
|
pod: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "pod-0",
|
Name: "pod-0",
|
||||||
@ -453,9 +471,8 @@ func TestSkipPodUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
// Pod update (with changes on ResourceVersion, Spec.NodeName and/or
|
|
||||||
// Annotations) for an already assumed pod should be skipped.
|
|
||||||
{
|
{
|
||||||
|
name: "with changes on ResourceVersion, Spec.NodeName and/or Annotations",
|
||||||
pod: &v1.Pod{
|
pod: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "pod-0",
|
Name: "pod-0",
|
||||||
@ -483,9 +500,8 @@ func TestSkipPodUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
// Pod update (with changes on Labels) for an already assumed pod
|
|
||||||
// should not be skipped.
|
|
||||||
{
|
{
|
||||||
|
name: "with changes on Labels",
|
||||||
pod: &v1.Pod{
|
pod: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "pod-0",
|
Name: "pod-0",
|
||||||
@ -505,17 +521,20 @@ func TestSkipPodUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
} {
|
}
|
||||||
c := &configFactory{
|
for _, test := range table {
|
||||||
schedulerCache: &schedulertesting.FakeCache{
|
t.Run(test.name, func(t *testing.T) {
|
||||||
IsAssumedPodFunc: test.isAssumedPodFunc,
|
c := &configFactory{
|
||||||
GetPodFunc: test.getPodFunc,
|
schedulerCache: &schedulertesting.FakeCache{
|
||||||
},
|
IsAssumedPodFunc: test.isAssumedPodFunc,
|
||||||
}
|
GetPodFunc: test.getPodFunc,
|
||||||
got := c.skipPodUpdate(test.pod)
|
},
|
||||||
if got != test.expected {
|
}
|
||||||
t.Errorf("skipPodUpdate() = %t, expected = %t", got, test.expected)
|
got := c.skipPodUpdate(test.pod)
|
||||||
}
|
if got != test.expected {
|
||||||
|
t.Errorf("skipPodUpdate() = %t, expected = %t", got, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,24 +612,22 @@ func (f *fakeExtender) IsInterested(pod *v1.Pod) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBinderFunc(t *testing.T) {
|
func TestGetBinderFunc(t *testing.T) {
|
||||||
for _, test := range []struct {
|
table := []struct {
|
||||||
podName string
|
podName string
|
||||||
extenders []algorithm.SchedulerExtender
|
extenders []algorithm.SchedulerExtender
|
||||||
|
|
||||||
expectedBinderType string
|
expectedBinderType string
|
||||||
|
name string
|
||||||
}{
|
}{
|
||||||
// Expect to return the default binder because the extender is not a
|
|
||||||
// binder, even though it's interested in the pod.
|
|
||||||
{
|
{
|
||||||
|
name: "the extender is not a binder",
|
||||||
podName: "pod0",
|
podName: "pod0",
|
||||||
extenders: []algorithm.SchedulerExtender{
|
extenders: []algorithm.SchedulerExtender{
|
||||||
&fakeExtender{isBinder: false, interestedPodName: "pod0"},
|
&fakeExtender{isBinder: false, interestedPodName: "pod0"},
|
||||||
},
|
},
|
||||||
expectedBinderType: "*factory.binder",
|
expectedBinderType: "*factory.binder",
|
||||||
},
|
},
|
||||||
// Expect to return the fake binder because one of the extenders is a
|
|
||||||
// binder and it's interested in the pod.
|
|
||||||
{
|
{
|
||||||
|
name: "one of the extenders is a binder and interested in pod",
|
||||||
podName: "pod0",
|
podName: "pod0",
|
||||||
extenders: []algorithm.SchedulerExtender{
|
extenders: []algorithm.SchedulerExtender{
|
||||||
&fakeExtender{isBinder: false, interestedPodName: "pod0"},
|
&fakeExtender{isBinder: false, interestedPodName: "pod0"},
|
||||||
@ -618,9 +635,8 @@ func TestGetBinderFunc(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedBinderType: "*factory.fakeExtender",
|
expectedBinderType: "*factory.fakeExtender",
|
||||||
},
|
},
|
||||||
// Expect to return the default binder because one of the extenders is
|
|
||||||
// a binder but the binder is not interested in the pod.
|
|
||||||
{
|
{
|
||||||
|
name: "one of the extenders is a binder, but not interested in pod",
|
||||||
podName: "pod1",
|
podName: "pod1",
|
||||||
extenders: []algorithm.SchedulerExtender{
|
extenders: []algorithm.SchedulerExtender{
|
||||||
&fakeExtender{isBinder: false, interestedPodName: "pod1"},
|
&fakeExtender{isBinder: false, interestedPodName: "pod1"},
|
||||||
@ -628,20 +644,28 @@ func TestGetBinderFunc(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedBinderType: "*factory.binder",
|
expectedBinderType: "*factory.binder",
|
||||||
},
|
},
|
||||||
} {
|
}
|
||||||
pod := &v1.Pod{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: test.podName,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
f := &configFactory{}
|
for _, test := range table {
|
||||||
binderFunc := f.getBinderFunc(test.extenders)
|
t.Run(test.name, func(t *testing.T) {
|
||||||
binder := binderFunc(pod)
|
testGetBinderFunc(test.expectedBinderType, test.podName, test.extenders, t)
|
||||||
|
})
|
||||||
binderType := fmt.Sprintf("%s", reflect.TypeOf(binder))
|
}
|
||||||
if binderType != test.expectedBinderType {
|
}
|
||||||
t.Errorf("Expected binder %q but got %q", test.expectedBinderType, binderType)
|
|
||||||
}
|
func testGetBinderFunc(expectedBinderType, podName string, extenders []algorithm.SchedulerExtender, t *testing.T) {
|
||||||
|
pod := &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: podName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
f := &configFactory{}
|
||||||
|
binderFunc := f.getBinderFunc(extenders)
|
||||||
|
binder := binderFunc(pod)
|
||||||
|
|
||||||
|
binderType := fmt.Sprintf("%s", reflect.TypeOf(binder))
|
||||||
|
if binderType != expectedBinderType {
|
||||||
|
t.Errorf("Expected binder %q but got %q", expectedBinderType, binderType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,14 +36,18 @@ func TestAlgorithmNameValidation(t *testing.T) {
|
|||||||
"Some,Alg:orithm",
|
"Some,Alg:orithm",
|
||||||
}
|
}
|
||||||
for _, name := range algorithmNamesShouldValidate {
|
for _, name := range algorithmNamesShouldValidate {
|
||||||
if !validName.MatchString(name) {
|
t.Run(name, func(t *testing.T) {
|
||||||
t.Errorf("%v should be a valid algorithm name but is not valid.", name)
|
if !validName.MatchString(name) {
|
||||||
}
|
t.Errorf("should be a valid algorithm name but is not valid.")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
for _, name := range algorithmNamesShouldNotValidate {
|
for _, name := range algorithmNamesShouldNotValidate {
|
||||||
if validName.MatchString(name) {
|
t.Run(name, func(t *testing.T) {
|
||||||
t.Errorf("%v should be an invalid algorithm name but is valid.", name)
|
if validName.MatchString(name) {
|
||||||
}
|
t.Errorf("should be an invalid algorithm name but is valid.")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,16 +74,18 @@ func TestValidatePriorityConfigOverFlow(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
err := validateSelectedConfigs(test.configs)
|
t.Run(test.description, func(t *testing.T) {
|
||||||
if test.expected {
|
err := validateSelectedConfigs(test.configs)
|
||||||
if err == nil {
|
if test.expected {
|
||||||
t.Errorf("Expected Overflow for %s", test.description)
|
if err == nil {
|
||||||
|
t.Errorf("Expected Overflow")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Did not expect an overflow")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Did not expect an overflow for %s", test.description)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user