@@ -33,8 +33,10 @@ import (
33
33
"k8s.io/component-base/metrics/legacyregistry"
34
34
"k8s.io/component-base/metrics/testutil"
35
35
"k8s.io/component-helpers/storage/volume"
36
+ configv1 "k8s.io/kube-scheduler/config/v1"
36
37
"k8s.io/kubernetes/pkg/features"
37
38
"k8s.io/kubernetes/pkg/scheduler"
39
+ configtesting "k8s.io/kubernetes/pkg/scheduler/apis/config/testing"
38
40
"k8s.io/kubernetes/pkg/scheduler/framework"
39
41
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/names"
40
42
st "k8s.io/kubernetes/pkg/scheduler/testing"
@@ -76,6 +78,10 @@ type CoreResourceEnqueueTestCase struct {
76
78
// EnableSchedulingQueueHint indicates which feature gate value(s) the test case should run with.
77
79
// By default, it's {true, false}
78
80
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
79
85
}
80
86
81
87
var (
@@ -2063,8 +2069,9 @@ var CoreResourceEnqueueTestCases = []*CoreResourceEnqueueTestCase{
2063
2069
WantRequeuedPods : sets .New ("pod2" ),
2064
2070
},
2065
2071
{
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" },
2068
2075
InitialPVs : []* v1.PersistentVolume {
2069
2076
st .MakePersistentVolume ().Name ("pv1" ).
2070
2077
AccessModes ([]v1.PersistentVolumeAccessMode {v1 .ReadWriteMany }).
@@ -2076,11 +2083,6 @@ var CoreResourceEnqueueTestCases = []*CoreResourceEnqueueTestCase{
2076
2083
Capacity (v1.ResourceList {v1 .ResourceStorage : resource .MustParse ("1Mi" )}).
2077
2084
PersistentVolumeSource (v1.PersistentVolumeSource {CSI : & v1.CSIPersistentVolumeSource {Driver : "csidriver" , VolumeHandle : "volumehandle2" }}).
2078
2085
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 (),
2084
2086
},
2085
2087
InitialPVCs : []* v1.PersistentVolumeClaim {
2086
2088
st .MakePersistentVolumeClaim ().
@@ -2090,21 +2092,6 @@ var CoreResourceEnqueueTestCases = []*CoreResourceEnqueueTestCase{
2090
2092
AccessModes ([]v1.PersistentVolumeAccessMode {v1 .ReadWriteOncePod }).
2091
2093
Resources (v1.VolumeResourceRequirements {Requests : v1.ResourceList {v1 .ResourceStorage : resource .MustParse ("1Mi" )}}).
2092
2094
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 (),
2108
2095
},
2109
2096
InitialCSIDrivers : []* storagev1.CSIDriver {
2110
2097
st .MakeCSIDriver ().Name ("csidriver" ).StorageCapacity (ptr .To (true )).Obj (),
@@ -2119,13 +2106,8 @@ var CoreResourceEnqueueTestCases = []*CoreResourceEnqueueTestCase{
2119
2106
},
2120
2107
Pods : []* v1.Pod {
2121
2108
st .MakePod ().Name ("pod2" ).Container ("image" ).PVC ("pvc2" ).Obj (),
2122
- st .MakePod ().Name ("pod3" ).Container ("image" ).PVC ("pvc3" ).Obj (),
2123
2109
},
2124
2110
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
-
2129
2111
pvc := st .MakePersistentVolumeClaim ().
2130
2112
Name ("pvc2" ).
2131
2113
Annotation (volume .AnnBindCompleted , "true" ).
@@ -2149,15 +2131,41 @@ func RunTestCoreResourceEnqueue(t *testing.T, tt *CoreResourceEnqueueTestCase) {
2149
2131
t .Helper ()
2150
2132
featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .InPlacePodVerticalScaling , true )
2151
2133
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
+
2152
2161
// Use zero backoff seconds to bypass backoffQ.
2153
2162
// It's intended to not start the scheduler's queue, and hence to
2154
2163
// not start any flushing logic. We will pop and schedule the Pods manually later.
2155
2164
testCtx := testutils .InitTestSchedulerWithOptions (
2156
2165
t ,
2157
2166
testutils .InitTestAPIServer (t , "core-res-enqueue" , nil ),
2158
2167
0 ,
2159
- scheduler .WithPodInitialBackoffSeconds (0 ),
2160
- scheduler .WithPodMaxBackoffSeconds (0 ),
2168
+ opts ... ,
2161
2169
)
2162
2170
testutils .SyncSchedulerInformerFactory (testCtx )
2163
2171
0 commit comments