@@ -21,6 +21,7 @@ import (
21
21
"encoding/json"
22
22
"errors"
23
23
"fmt"
24
+ "math"
24
25
"math/rand"
25
26
"sort"
26
27
"strings"
@@ -142,13 +143,20 @@ func (pl *TestPlugin) Filter(ctx context.Context, state *framework.CycleState, p
142
143
return nil
143
144
}
144
145
146
+ const (
147
+ LabelKeyIsViolatingPDB = "test.kubernetes.io/is-violating-pdb"
148
+ LabelValueViolatingPDB = "violating"
149
+ LabelValueNonViolatingPDB = "non-violating"
150
+ )
151
+
145
152
func TestPostFilter (t * testing.T ) {
146
153
onePodRes := map [v1.ResourceName ]string {v1 .ResourcePods : "1" }
147
154
nodeRes := map [v1.ResourceName ]string {v1 .ResourceCPU : "200m" , v1 .ResourceMemory : "400" }
148
155
tests := []struct {
149
156
name string
150
157
pod * v1.Pod
151
158
pods []* v1.Pod
159
+ pdbs []* policy.PodDisruptionBudget
152
160
nodes []* v1.Node
153
161
filteredNodesStatuses framework.NodeToStatusMap
154
162
extender framework.Extender
@@ -218,6 +226,29 @@ func TestPostFilter(t *testing.T) {
218
226
wantResult : framework .NewPostFilterResultWithNominatedNode ("node2" ),
219
227
wantStatus : framework .NewStatus (framework .Success ),
220
228
},
229
+ {
230
+ name : "pod can be made schedulable on minHighestPriority node" ,
231
+ pod : st .MakePod ().Name ("p" ).UID ("p" ).Namespace (v1 .NamespaceDefault ).Priority (veryHighPriority ).Obj (),
232
+ pods : []* v1.Pod {
233
+ st .MakePod ().Name ("p1" ).UID ("p1" ).Label (LabelKeyIsViolatingPDB , LabelValueNonViolatingPDB ).Namespace (v1 .NamespaceDefault ).Priority (highPriority ).Node ("node1" ).Obj (),
234
+ st .MakePod ().Name ("p2" ).UID ("p2" ).Label (LabelKeyIsViolatingPDB , LabelValueViolatingPDB ).Namespace (v1 .NamespaceDefault ).Priority (lowPriority ).Node ("node1" ).Obj (),
235
+ st .MakePod ().Name ("p3" ).UID ("p3" ).Label (LabelKeyIsViolatingPDB , LabelValueViolatingPDB ).Namespace (v1 .NamespaceDefault ).Priority (midPriority ).Node ("node2" ).Obj (),
236
+ },
237
+ pdbs : []* policy.PodDisruptionBudget {
238
+ st .MakePDB ().Name ("violating-pdb" ).Namespace (v1 .NamespaceDefault ).MatchLabel (LabelKeyIsViolatingPDB , LabelValueViolatingPDB ).MinAvailable ("100%" ).Obj (),
239
+ st .MakePDB ().Name ("non-violating-pdb" ).Namespace (v1 .NamespaceDefault ).MatchLabel (LabelKeyIsViolatingPDB , LabelValueNonViolatingPDB ).MinAvailable ("0" ).DisruptionsAllowed (math .MaxInt32 ).Obj (),
240
+ },
241
+ nodes : []* v1.Node {
242
+ st .MakeNode ().Name ("node1" ).Capacity (onePodRes ).Obj (),
243
+ st .MakeNode ().Name ("node2" ).Capacity (onePodRes ).Obj (),
244
+ },
245
+ filteredNodesStatuses : framework.NodeToStatusMap {
246
+ "node1" : framework .NewStatus (framework .Unschedulable ),
247
+ "node2" : framework .NewStatus (framework .Unschedulable ),
248
+ },
249
+ wantResult : framework .NewPostFilterResultWithNominatedNode ("node2" ),
250
+ wantStatus : framework .NewStatus (framework .Success ),
251
+ },
221
252
{
222
253
name : "preemption result filtered out by extenders" ,
223
254
pod : st .MakePod ().Name ("p" ).UID ("p" ).Namespace (v1 .NamespaceDefault ).Priority (highPriority ).Obj (),
@@ -347,6 +378,13 @@ func TestPostFilter(t *testing.T) {
347
378
for i := range tt .pods {
348
379
podInformer .GetStore ().Add (tt .pods [i ])
349
380
}
381
+ pdbInformer := informerFactory .Policy ().V1 ().PodDisruptionBudgets ().Informer ()
382
+ for i := range tt .pdbs {
383
+ if err := pdbInformer .GetStore ().Add (tt .pdbs [i ]); err != nil {
384
+ t .Fatal (err )
385
+ }
386
+ }
387
+
350
388
// Register NodeResourceFit as the Filter & PreFilter plugin.
351
389
registeredPlugins := []tf.RegisterPluginFunc {
352
390
tf .RegisterQueueSortPlugin (queuesort .Name , queuesort .New ),
0 commit comments