...
1
16
17 package bind
18
19 import (
20 "testing"
21
22 corev1 "k8s.io/api/core/v1"
23 "k8s.io/kubernetes/pkg/scheduler/framework"
24 st "k8s.io/kubernetes/pkg/scheduler/testing"
25 testutil "k8s.io/kubernetes/test/integration/util"
26 )
27
28
29 func TestDefaultBinder(t *testing.T) {
30 testCtx := testutil.InitTestSchedulerWithOptions(t, testutil.InitTestAPIServer(t, "", nil), 0)
31 testutil.SyncSchedulerInformerFactory(testCtx)
32
33
34 node, err := testutil.CreateNode(testCtx.ClientSet, st.MakeNode().Name("testnode").Obj())
35 if err != nil {
36 t.Fatal(err)
37 }
38
39 tests := map[string]struct {
40 anotherUID bool
41 wantStatusCode framework.Code
42 }{
43 "same UID": {
44 wantStatusCode: framework.Success,
45 },
46 "different UID": {
47 anotherUID: true,
48 wantStatusCode: framework.Error,
49 },
50 }
51 for name, tc := range tests {
52 t.Run(name, func(t *testing.T) {
53 pod, err := testutil.CreatePausePodWithResource(testCtx.ClientSet, "fixed-name", testCtx.NS.Name, nil)
54 if err != nil {
55 t.Fatalf("Failed to create pod: %v", err)
56 }
57 defer testutil.CleanupPods(testCtx.Ctx, testCtx.ClientSet, t, []*corev1.Pod{pod})
58
59 podCopy := pod.DeepCopy()
60 if tc.anotherUID {
61 podCopy.UID = "another"
62 }
63
64 status := testCtx.Scheduler.Profiles["default-scheduler"].RunBindPlugins(testCtx.Ctx, nil, podCopy, node.Name)
65 if code := status.Code(); code != tc.wantStatusCode {
66 t.Errorf("Bind returned code %s, want %s", code, tc.wantStatusCode)
67 }
68 })
69 }
70 }
71
View as plain text