mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-17 23:19:26 +00:00
Add unit and integration tests for multiple profiles support
Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
@@ -49,6 +49,7 @@ go_test(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/admission:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/informers:go_default_library",
|
||||
|
@@ -25,12 +25,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/informers"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
corelisters "k8s.io/client-go/listers/core/v1"
|
||||
@@ -595,6 +595,76 @@ func TestMultipleSchedulers(t *testing.T) {
|
||||
*/
|
||||
}
|
||||
|
||||
func TestMultipleSchedulingProfiles(t *testing.T) {
|
||||
testCtx := initTest(t, "multi-scheduler", scheduler.WithProfiles(
|
||||
kubeschedulerconfig.KubeSchedulerProfile{
|
||||
SchedulerName: "default-scheduler",
|
||||
},
|
||||
kubeschedulerconfig.KubeSchedulerProfile{
|
||||
SchedulerName: "custom-scheduler",
|
||||
},
|
||||
))
|
||||
defer cleanupTest(t, testCtx)
|
||||
|
||||
node := &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "node-multi-scheduler-test-node"},
|
||||
Spec: v1.NodeSpec{Unschedulable: false},
|
||||
Status: v1.NodeStatus{
|
||||
Capacity: v1.ResourceList{
|
||||
v1.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := testCtx.clientSet.CoreV1().Nodes().Create(context.TODO(), node, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
evs, err := testCtx.clientSet.CoreV1().Events(testCtx.ns.Name).Watch(testCtx.ctx, metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer evs.Stop()
|
||||
|
||||
for _, pc := range []*pausePodConfig{
|
||||
{Name: "foo", Namespace: testCtx.ns.Name},
|
||||
{Name: "bar", Namespace: testCtx.ns.Name, SchedulerName: "unknown-scheduler"},
|
||||
{Name: "baz", Namespace: testCtx.ns.Name, SchedulerName: "default-scheduler"},
|
||||
{Name: "zet", Namespace: testCtx.ns.Name, SchedulerName: "custom-scheduler"},
|
||||
} {
|
||||
if _, err := createPausePod(testCtx.clientSet, initPausePod(testCtx.clientSet, pc)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
wantProfiles := map[string]string{
|
||||
"foo": "default-scheduler",
|
||||
"baz": "default-scheduler",
|
||||
"zet": "custom-scheduler",
|
||||
}
|
||||
|
||||
gotProfiles := make(map[string]string)
|
||||
if err := wait.Poll(100*time.Millisecond, 30*time.Second, func() (bool, error) {
|
||||
var ev watch.Event
|
||||
select {
|
||||
case ev = <-evs.ResultChan():
|
||||
case <-time.After(30 * time.Second):
|
||||
return false, nil
|
||||
}
|
||||
e, ok := ev.Object.(*v1.Event)
|
||||
if !ok || e.Reason != "Scheduled" {
|
||||
return false, nil
|
||||
}
|
||||
gotProfiles[e.InvolvedObject.Name] = e.ReportingController
|
||||
return len(gotProfiles) >= len(wantProfiles), nil
|
||||
}); err != nil {
|
||||
t.Errorf("waiting for scheduling events: %v", err)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(wantProfiles, gotProfiles); diff != "" {
|
||||
t.Errorf("pods scheduled by the wrong profile (-want, +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
// This test will verify scheduler can work well regardless of whether kubelet is allocatable aware or not.
|
||||
func TestAllocatable(t *testing.T) {
|
||||
testCtx := initTest(t, "allocatable")
|
||||
|
@@ -242,8 +242,8 @@ func initDisruptionController(t *testing.T, testCtx *testContext) *disruption.Di
|
||||
|
||||
// initTest initializes a test environment and creates master and scheduler with default
|
||||
// configuration.
|
||||
func initTest(t *testing.T, nsPrefix string) *testContext {
|
||||
return initTestScheduler(t, initTestMaster(t, nsPrefix, nil), true, nil)
|
||||
func initTest(t *testing.T, nsPrefix string, opts ...scheduler.Option) *testContext {
|
||||
return initTestSchedulerWithOptions(t, initTestMaster(t, nsPrefix, nil), true, nil, time.Second, opts...)
|
||||
}
|
||||
|
||||
// initTestDisablePreemption initializes a test environment and creates master and scheduler with default
|
||||
|
Reference in New Issue
Block a user