k8s.io/kubernetes@v1.29.3/test/integration/scheduler/bind/bind_test.go (about) 1 /* 2 Copyright 2023 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 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 // TestDefaultBinder tests the binding process in the scheduler. 29 func TestDefaultBinder(t *testing.T) { 30 testCtx := testutil.InitTestSchedulerWithOptions(t, testutil.InitTestAPIServer(t, "", nil), 0) 31 testutil.SyncSchedulerInformerFactory(testCtx) 32 33 // Add a node. 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 }