Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an integration test flake on NodeAfffinity ScorePlugin #93495

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/integration/scheduler/BUILD
Expand Up @@ -29,6 +29,10 @@ go_test(
"//pkg/scheduler:go_default_library",
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/plugins/defaultbinder:go_default_library",
"//pkg/scheduler/framework/plugins/imagelocality:go_default_library",
"//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library",
"//pkg/scheduler/framework/plugins/nodeaffinity:go_default_library",
"//pkg/scheduler/framework/plugins/podtopologyspread:go_default_library",
"//pkg/scheduler/framework/runtime:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/profile:go_default_library",
Expand Down
45 changes: 39 additions & 6 deletions test/integration/scheduler/priorities_test.go
Expand Up @@ -26,17 +26,50 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/kubernetes/pkg/scheduler"
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/imagelocality"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/podtopologyspread"
st "k8s.io/kubernetes/pkg/scheduler/testing"
testutils "k8s.io/kubernetes/test/integration/util"
imageutils "k8s.io/kubernetes/test/utils/image"
)

// This file tests the scheduler priority functions.

func initTestSchedulerForPriorityTest(t *testing.T, scorePluginName string) *testutils.TestContext {
prof := schedulerconfig.KubeSchedulerProfile{
SchedulerName: v1.DefaultSchedulerName,
Plugins: &schedulerconfig.Plugins{
Score: &schedulerconfig.PluginSet{
Enabled: []schedulerconfig.Plugin{
{Name: scorePluginName, Weight: 1},
},
Disabled: []schedulerconfig.Plugin{
{Name: "*"},
},
},
},
}
testCtx := testutils.InitTestSchedulerWithOptions(
t,
testutils.InitTestMaster(t, strings.ToLower(scorePluginName), nil),
false,
nil,
0,
scheduler.WithProfiles(prof),
)
testutils.SyncInformerFactory(testCtx)
go testCtx.Scheduler.Run(testCtx.Ctx)
return testCtx
}

// TestNodeAffinity verifies that scheduler's node affinity priority function
// works correctly.
// works correctly.s
func TestNodeAffinity(t *testing.T) {
testCtx := initTest(t, "node-affinity")
testCtx := initTestSchedulerForPriorityTest(t, nodeaffinity.Name)
defer testutils.CleanupTest(t, testCtx)
// Add a few nodes.
_, err := createNodes(testCtx.ClientSet, "testnode", st.MakeNode(), 4)
Expand Down Expand Up @@ -88,7 +121,7 @@ func TestNodeAffinity(t *testing.T) {
// TestPodAffinity verifies that scheduler's pod affinity priority function
// works correctly.
func TestPodAffinity(t *testing.T) {
testCtx := initTest(t, "pod-affinity")
testCtx := initTestSchedulerForPriorityTest(t, interpodaffinity.Name)
defer testutils.CleanupTest(t, testCtx)
// Add a few nodes.
topologyKey := "node-topologykey"
Expand Down Expand Up @@ -166,7 +199,7 @@ func TestPodAffinity(t *testing.T) {
// TestImageLocality verifies that the scheduler's image locality priority function
// works correctly, i.e., the pod gets scheduled to the node where its container images are ready.
func TestImageLocality(t *testing.T) {
testCtx := initTest(t, "image-locality")
testCtx := initTestSchedulerForPriorityTest(t, imagelocality.Name)
defer testutils.CleanupTest(t, testCtx)

// Create a node with the large image.
Expand Down Expand Up @@ -224,10 +257,10 @@ func makeContainersWithImages(images []string) []v1.Container {

// TestEvenPodsSpreadPriority verifies that EvenPodsSpread priority functions well.
func TestEvenPodsSpreadPriority(t *testing.T) {
testCtx := initTest(t, "eps-priority")
testCtx := initTestSchedulerForPriorityTest(t, podtopologyspread.Name)
defer testutils.CleanupTest(t, testCtx)
cs := testCtx.ClientSet
ns := testCtx.NS.Name
defer testutils.CleanupTest(t, testCtx)

var nodes []*v1.Node
for i := 0; i < 4; i++ {
Expand Down