Skip to content

Commit d8d3691

Browse files
authored
Merge pull request kubernetes#129360 from utam0k/scheduler-profile-test-enqueue
Make it possible to pass a scheduler profile to RuntTestCoreResourceEnqueue
2 parents 9fc9ddc + 5aa4dd4 commit d8d3691

File tree

1 file changed

+37
-29
lines changed
  • test/integration/scheduler/queueing

1 file changed

+37
-29
lines changed

test/integration/scheduler/queueing/queue.go

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ import (
3333
"k8s.io/component-base/metrics/legacyregistry"
3434
"k8s.io/component-base/metrics/testutil"
3535
"k8s.io/component-helpers/storage/volume"
36+
configv1 "k8s.io/kube-scheduler/config/v1"
3637
"k8s.io/kubernetes/pkg/features"
3738
"k8s.io/kubernetes/pkg/scheduler"
39+
configtesting "k8s.io/kubernetes/pkg/scheduler/apis/config/testing"
3840
"k8s.io/kubernetes/pkg/scheduler/framework"
3941
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/names"
4042
st "k8s.io/kubernetes/pkg/scheduler/testing"
@@ -76,6 +78,10 @@ type CoreResourceEnqueueTestCase struct {
7678
// EnableSchedulingQueueHint indicates which feature gate value(s) the test case should run with.
7779
// By default, it's {true, false}
7880
EnableSchedulingQueueHint sets.Set[bool]
81+
// EnablePlugins is a list of plugins to enable.
82+
// PrioritySort and DefaultPreemption are enabled by default because they are required by the framework.
83+
// If empty, all plugins are enabled.
84+
EnablePlugins []string
7985
}
8086

8187
var (
@@ -2063,8 +2069,9 @@ var CoreResourceEnqueueTestCases = []*CoreResourceEnqueueTestCase{
20632069
WantRequeuedPods: sets.New("pod2"),
20642070
},
20652071
{
2066-
Name: "Pod rejected with PVC by the CSI plugin is requeued when the related PVC is added",
2067-
InitialNodes: []*v1.Node{st.MakeNode().Name("fake-node").Label("node", "fake-node").Obj()},
2072+
Name: "Pod rejected with PVC by the CSI plugin is requeued when the related PVC is added",
2073+
InitialNodes: []*v1.Node{st.MakeNode().Name("fake-node").Label("node", "fake-node").Obj()},
2074+
EnablePlugins: []string{"VolumeBinding"},
20682075
InitialPVs: []*v1.PersistentVolume{
20692076
st.MakePersistentVolume().Name("pv1").
20702077
AccessModes([]v1.PersistentVolumeAccessMode{v1.ReadWriteMany}).
@@ -2076,11 +2083,6 @@ var CoreResourceEnqueueTestCases = []*CoreResourceEnqueueTestCase{
20762083
Capacity(v1.ResourceList{v1.ResourceStorage: resource.MustParse("1Mi")}).
20772084
PersistentVolumeSource(v1.PersistentVolumeSource{CSI: &v1.CSIPersistentVolumeSource{Driver: "csidriver", VolumeHandle: "volumehandle2"}}).
20782085
Obj(),
2079-
st.MakePersistentVolume().Name("pv3").
2080-
AccessModes([]v1.PersistentVolumeAccessMode{v1.ReadWriteMany}).
2081-
Capacity(v1.ResourceList{v1.ResourceStorage: resource.MustParse("1Mi")}).
2082-
PersistentVolumeSource(v1.PersistentVolumeSource{CSI: &v1.CSIPersistentVolumeSource{Driver: "csidriver", VolumeHandle: "volumehandle3"}}).
2083-
Obj(),
20842086
},
20852087
InitialPVCs: []*v1.PersistentVolumeClaim{
20862088
st.MakePersistentVolumeClaim().
@@ -2090,21 +2092,6 @@ var CoreResourceEnqueueTestCases = []*CoreResourceEnqueueTestCase{
20902092
AccessModes([]v1.PersistentVolumeAccessMode{v1.ReadWriteOncePod}).
20912093
Resources(v1.VolumeResourceRequirements{Requests: v1.ResourceList{v1.ResourceStorage: resource.MustParse("1Mi")}}).
20922094
Obj(),
2093-
// If we don't have pvc2, it's filtered by the VolumeBinding pluging, so we should create it first and recreate it in a triggerFn.
2094-
st.MakePersistentVolumeClaim().
2095-
Name("pvc2").
2096-
Annotation(volume.AnnBindCompleted, "true").
2097-
VolumeName("pv2").
2098-
AccessModes([]v1.PersistentVolumeAccessMode{v1.ReadWriteOncePod}).
2099-
Resources(v1.VolumeResourceRequirements{Requests: v1.ResourceList{v1.ResourceStorage: resource.MustParse("1Mi")}}).
2100-
Obj(),
2101-
st.MakePersistentVolumeClaim().
2102-
Name("pvc3").
2103-
Annotation(volume.AnnBindCompleted, "true").
2104-
VolumeName("pv3").
2105-
AccessModes([]v1.PersistentVolumeAccessMode{v1.ReadWriteOncePod}).
2106-
Resources(v1.VolumeResourceRequirements{Requests: v1.ResourceList{v1.ResourceStorage: resource.MustParse("1Mi")}}).
2107-
Obj(),
21082095
},
21092096
InitialCSIDrivers: []*storagev1.CSIDriver{
21102097
st.MakeCSIDriver().Name("csidriver").StorageCapacity(ptr.To(true)).Obj(),
@@ -2119,13 +2106,8 @@ var CoreResourceEnqueueTestCases = []*CoreResourceEnqueueTestCase{
21192106
},
21202107
Pods: []*v1.Pod{
21212108
st.MakePod().Name("pod2").Container("image").PVC("pvc2").Obj(),
2122-
st.MakePod().Name("pod3").Container("image").PVC("pvc3").Obj(),
21232109
},
21242110
TriggerFn: func(testCtx *testutils.TestContext) (map[framework.ClusterEvent]uint64, error) {
2125-
if err := testCtx.ClientSet.CoreV1().PersistentVolumeClaims(testCtx.NS.Name).Delete(testCtx.Ctx, "pvc2", metav1.DeleteOptions{}); err != nil {
2126-
return nil, fmt.Errorf("failed to delete pvc2: %w", err)
2127-
}
2128-
21292111
pvc := st.MakePersistentVolumeClaim().
21302112
Name("pvc2").
21312113
Annotation(volume.AnnBindCompleted, "true").
@@ -2149,15 +2131,41 @@ func RunTestCoreResourceEnqueue(t *testing.T, tt *CoreResourceEnqueueTestCase) {
21492131
t.Helper()
21502132
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.InPlacePodVerticalScaling, true)
21512133

2134+
opts := []scheduler.Option{scheduler.WithPodInitialBackoffSeconds(0), scheduler.WithPodMaxBackoffSeconds(0)}
2135+
if tt.EnablePlugins != nil {
2136+
enablePlugins := []configv1.Plugin{
2137+
// These are required plugins to start the scheduler.
2138+
{Name: "PrioritySort"},
2139+
{Name: "DefaultBinder"},
2140+
}
2141+
for _, pluginName := range tt.EnablePlugins {
2142+
enablePlugins = append(enablePlugins, configv1.Plugin{Name: pluginName})
2143+
}
2144+
profile := configv1.KubeSchedulerProfile{
2145+
SchedulerName: ptr.To("default-scheduler"),
2146+
Plugins: &configv1.Plugins{
2147+
MultiPoint: configv1.PluginSet{
2148+
Enabled: enablePlugins,
2149+
Disabled: []configv1.Plugin{
2150+
{Name: "*"},
2151+
},
2152+
},
2153+
},
2154+
}
2155+
cfg := configtesting.V1ToInternalWithDefaults(t, configv1.KubeSchedulerConfiguration{
2156+
Profiles: []configv1.KubeSchedulerProfile{profile},
2157+
})
2158+
opts = append(opts, scheduler.WithProfiles(cfg.Profiles...))
2159+
}
2160+
21522161
// Use zero backoff seconds to bypass backoffQ.
21532162
// It's intended to not start the scheduler's queue, and hence to
21542163
// not start any flushing logic. We will pop and schedule the Pods manually later.
21552164
testCtx := testutils.InitTestSchedulerWithOptions(
21562165
t,
21572166
testutils.InitTestAPIServer(t, "core-res-enqueue", nil),
21582167
0,
2159-
scheduler.WithPodInitialBackoffSeconds(0),
2160-
scheduler.WithPodMaxBackoffSeconds(0),
2168+
opts...,
21612169
)
21622170
testutils.SyncSchedulerInformerFactory(testCtx)
21632171

0 commit comments

Comments
 (0)