From d1dfa899532ae503a81f2ffdd80aa3f734af97e9 Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor Date: Mon, 13 Mar 2023 16:50:57 -0400 Subject: [PATCH] Add integration test for DefaultBinder Change-Id: I71ea08104024403a7d9ebcf3725fc3ff17997229 --- test/integration/scheduler/bind/bind_test.go | 72 ++++++++++++++++++++ test/integration/scheduler/bind/main_test.go | 27 ++++++++ 2 files changed, 99 insertions(+) create mode 100644 test/integration/scheduler/bind/bind_test.go create mode 100644 test/integration/scheduler/bind/main_test.go diff --git a/test/integration/scheduler/bind/bind_test.go b/test/integration/scheduler/bind/bind_test.go new file mode 100644 index 00000000000..a633660aaea --- /dev/null +++ b/test/integration/scheduler/bind/bind_test.go @@ -0,0 +1,72 @@ +/* +Copyright 2023 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package bind + +import ( + "testing" + + corev1 "k8s.io/api/core/v1" + "k8s.io/kubernetes/pkg/scheduler/framework" + st "k8s.io/kubernetes/pkg/scheduler/testing" + testutil "k8s.io/kubernetes/test/integration/util" +) + +// TestDefaultBinder tests the binding process in the scheduler. +func TestDefaultBinder(t *testing.T) { + testCtx := testutil.InitTestSchedulerWithOptions(t, testutil.InitTestAPIServer(t, "", nil), 0) + testutil.SyncInformerFactory(testCtx) + // Do not start scheduler routine. + defer testutil.CleanupTest(t, testCtx) + + // Add a node. + node, err := testutil.CreateNode(testCtx.ClientSet, st.MakeNode().Name("testnode").Obj()) + if err != nil { + t.Fatal(err) + } + + tests := map[string]struct { + anotherUID bool + wantStatusCode framework.Code + }{ + "same UID": { + wantStatusCode: framework.Success, + }, + "different UID": { + anotherUID: true, + wantStatusCode: framework.Error, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + pod, err := testutil.CreatePausePodWithResource(testCtx.ClientSet, "fixed-name", testCtx.NS.Name, nil) + if err != nil { + t.Fatalf("Failed to create pod: %v", err) + } + defer testutil.CleanupPods(testCtx.ClientSet, t, []*corev1.Pod{pod}) + + podCopy := pod.DeepCopy() + if tc.anotherUID { + podCopy.UID = "another" + } + + status := testCtx.Scheduler.Profiles["default-scheduler"].RunBindPlugins(testCtx.Ctx, nil, podCopy, node.Name) + if code := status.Code(); code != tc.wantStatusCode { + t.Errorf("Bind returned code %s, want %s", code, tc.wantStatusCode) + } + }) + } +} diff --git a/test/integration/scheduler/bind/main_test.go b/test/integration/scheduler/bind/main_test.go new file mode 100644 index 00000000000..2ee98e1a006 --- /dev/null +++ b/test/integration/scheduler/bind/main_test.go @@ -0,0 +1,27 @@ +/* +Copyright 2023 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package bind + +import ( + "testing" + + "k8s.io/kubernetes/test/integration/framework" +) + +func TestMain(m *testing.M) { + framework.EtcdMain(m.Run) +}