@@ -21,8 +21,19 @@ import (
21
21
22
22
"github.com/google/go-cmp/cmp"
23
23
"k8s.io/apimachinery/pkg/util/sets"
24
+ "k8s.io/apiserver/pkg/util/feature"
25
+ "k8s.io/component-base/featuregate"
26
+ featuregatetesting "k8s.io/component-base/featuregate/testing"
27
+ "k8s.io/kubernetes/pkg/features"
24
28
"k8s.io/kubernetes/pkg/scheduler/apis/config"
29
+ "k8s.io/kubernetes/pkg/scheduler/framework/plugins/imagelocality"
30
+ "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
31
+ "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
32
+ "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodepreferavoidpods"
33
+ "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources"
25
34
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeunschedulable"
35
+ "k8s.io/kubernetes/pkg/scheduler/framework/plugins/podtopologyspread"
36
+ "k8s.io/kubernetes/pkg/scheduler/framework/plugins/selectorspread"
26
37
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
27
38
)
28
39
@@ -93,3 +104,152 @@ func TestRegisterConfigProducers(t *testing.T) {
93
104
t .Errorf ("unexpected plugin configuration (-want, +got): %s" , diff )
94
105
}
95
106
}
107
+
108
+ func TestAppendPriorityConfigs (t * testing.T ) {
109
+ cases := []struct {
110
+ name string
111
+ features map [featuregate.Feature ]bool
112
+ keys map [string ]int64
113
+ args ConfigProducerArgs
114
+ wantPlugins config.Plugins
115
+ wantPluginConfig []config.PluginConfig
116
+ }{
117
+ {
118
+ name : "default priorities" ,
119
+ wantPlugins : config.Plugins {
120
+ PreScore : & config.PluginSet {
121
+ Enabled : []config.Plugin {
122
+ {Name : podtopologyspread .Name },
123
+ {Name : interpodaffinity .Name },
124
+ {Name : selectorspread .Name },
125
+ {Name : tainttoleration .Name },
126
+ },
127
+ },
128
+ Score : & config.PluginSet {
129
+ Enabled : []config.Plugin {
130
+ {Name : noderesources .BalancedAllocationName , Weight : 1 },
131
+ {Name : podtopologyspread .Name , Weight : 2 },
132
+ {Name : imagelocality .Name , Weight : 1 },
133
+ {Name : interpodaffinity .Name , Weight : 1 },
134
+ {Name : noderesources .LeastAllocatedName , Weight : 1 },
135
+ {Name : nodeaffinity .Name , Weight : 1 },
136
+ {Name : nodepreferavoidpods .Name , Weight : 10000 },
137
+ {Name : selectorspread .Name , Weight : 1 },
138
+ {Name : tainttoleration .Name , Weight : 1 },
139
+ },
140
+ },
141
+ },
142
+ },
143
+ {
144
+ name : "DefaultPodTopologySpread enabled, SelectorSpreadPriority only" ,
145
+ features : map [featuregate.Feature ]bool {
146
+ features .DefaultPodTopologySpread : true ,
147
+ },
148
+ keys : map [string ]int64 {
149
+ SelectorSpreadPriority : 3 ,
150
+ },
151
+ wantPlugins : config.Plugins {
152
+ PreScore : & config.PluginSet {
153
+ Enabled : []config.Plugin {
154
+ {Name : podtopologyspread .Name },
155
+ },
156
+ },
157
+ Score : & config.PluginSet {
158
+ Enabled : []config.Plugin {
159
+ {Name : podtopologyspread .Name , Weight : 3 },
160
+ },
161
+ },
162
+ },
163
+ wantPluginConfig : []config.PluginConfig {
164
+ {
165
+ Name : podtopologyspread .Name ,
166
+ Args : & config.PodTopologySpreadArgs {
167
+ DefaultingType : config .SystemDefaulting ,
168
+ },
169
+ },
170
+ },
171
+ },
172
+ {
173
+ name : "DefaultPodTopologySpread enabled, EvenPodsSpreadPriority only" ,
174
+ features : map [featuregate.Feature ]bool {
175
+ features .DefaultPodTopologySpread : true ,
176
+ },
177
+ keys : map [string ]int64 {
178
+ EvenPodsSpreadPriority : 4 ,
179
+ },
180
+ wantPlugins : config.Plugins {
181
+ PreScore : & config.PluginSet {
182
+ Enabled : []config.Plugin {
183
+ {Name : podtopologyspread .Name },
184
+ },
185
+ },
186
+ Score : & config.PluginSet {
187
+ Enabled : []config.Plugin {
188
+ {Name : podtopologyspread .Name , Weight : 4 },
189
+ },
190
+ },
191
+ },
192
+ wantPluginConfig : []config.PluginConfig {
193
+ {
194
+ Name : podtopologyspread .Name ,
195
+ Args : & config.PodTopologySpreadArgs {
196
+ DefaultingType : config .ListDefaulting ,
197
+ },
198
+ },
199
+ },
200
+ },
201
+ {
202
+ name : "DefaultPodTopologySpread enabled, SelectorSpreadPriority+EvenPodsSpreadPriority" ,
203
+ features : map [featuregate.Feature ]bool {
204
+ features .DefaultPodTopologySpread : true ,
205
+ },
206
+ keys : map [string ]int64 {
207
+ SelectorSpreadPriority : 1 ,
208
+ EvenPodsSpreadPriority : 2 ,
209
+ },
210
+ wantPlugins : config.Plugins {
211
+ PreScore : & config.PluginSet {
212
+ Enabled : []config.Plugin {
213
+ {Name : podtopologyspread .Name },
214
+ },
215
+ },
216
+ Score : & config.PluginSet {
217
+ Enabled : []config.Plugin {
218
+ {Name : podtopologyspread .Name , Weight : 2 },
219
+ },
220
+ },
221
+ },
222
+ wantPluginConfig : []config.PluginConfig {
223
+ {
224
+ Name : podtopologyspread .Name ,
225
+ Args : & config.PodTopologySpreadArgs {
226
+ DefaultingType : config .SystemDefaulting ,
227
+ },
228
+ },
229
+ },
230
+ },
231
+ }
232
+ for _ , tc := range cases {
233
+ t .Run (tc .name , func (t * testing.T ) {
234
+ for k , v := range tc .features {
235
+ defer featuregatetesting .SetFeatureGateDuringTest (t , feature .DefaultFeatureGate , k , v )()
236
+ }
237
+
238
+ r := NewLegacyRegistry ()
239
+ keys := tc .keys
240
+ if keys == nil {
241
+ keys = r .DefaultPriorities
242
+ }
243
+ plugins , pluginConfig , err := r .AppendPriorityConfigs (keys , & tc .args , config.Plugins {}, nil )
244
+ if err != nil {
245
+ t .Fatalf ("Appending Priority Configs: %v" , err )
246
+ }
247
+ if diff := cmp .Diff (tc .wantPlugins , plugins ); diff != "" {
248
+ t .Errorf ("Unexpected Plugin (-want,+got):\n %s" , diff )
249
+ }
250
+ if diff := cmp .Diff (tc .wantPluginConfig , pluginConfig ); diff != "" {
251
+ t .Errorf ("Unexpected PluginConfig (-want,+got):\n %s" , diff )
252
+ }
253
+ })
254
+ }
255
+ }
0 commit comments