@@ -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"
@@ -144,6 +145,12 @@ func (pl *TestPlugin) Filter(ctx context.Context, state *framework.CycleState, p
144
145
return nil
145
146
}
146
147
148
+ const (
149
+ LabelKeyIsViolatingPDB = "test.kubernetes.io/is-violating-pdb"
150
+ LabelValueViolatingPDB = "violating"
151
+ LabelValueNonViolatingPDB = "non-violating"
152
+ )
153
+
147
154
func TestPostFilter (t * testing.T ) {
148
155
metrics .Register ()
149
156
onePodRes := map [v1.ResourceName ]string {v1 .ResourcePods : "1" }
@@ -152,6 +159,7 @@ func TestPostFilter(t *testing.T) {
152
159
name string
153
160
pod * v1.Pod
154
161
pods []* v1.Pod
162
+ pdbs []* policy.PodDisruptionBudget
155
163
nodes []* v1.Node
156
164
filteredNodesStatuses * framework.NodeToStatus
157
165
extender framework.Extender
@@ -234,6 +242,29 @@ func TestPostFilter(t *testing.T) {
234
242
wantResult : framework .NewPostFilterResultWithNominatedNode ("node2" ),
235
243
wantStatus : framework .NewStatus (framework .Success ),
236
244
},
245
+ {
246
+ name : "pod can be made schedulable on minHighestPriority node" ,
247
+ pod : st .MakePod ().Name ("p" ).UID ("p" ).Namespace (v1 .NamespaceDefault ).Priority (veryHighPriority ).Obj (),
248
+ pods : []* v1.Pod {
249
+ st .MakePod ().Name ("p1" ).UID ("p1" ).Label (LabelKeyIsViolatingPDB , LabelValueNonViolatingPDB ).Namespace (v1 .NamespaceDefault ).Priority (highPriority ).Node ("node1" ).Obj (),
250
+ st .MakePod ().Name ("p2" ).UID ("p2" ).Label (LabelKeyIsViolatingPDB , LabelValueViolatingPDB ).Namespace (v1 .NamespaceDefault ).Priority (lowPriority ).Node ("node1" ).Obj (),
251
+ st .MakePod ().Name ("p3" ).UID ("p3" ).Label (LabelKeyIsViolatingPDB , LabelValueViolatingPDB ).Namespace (v1 .NamespaceDefault ).Priority (midPriority ).Node ("node2" ).Obj (),
252
+ },
253
+ pdbs : []* policy.PodDisruptionBudget {
254
+ st .MakePDB ().Name ("violating-pdb" ).Namespace (v1 .NamespaceDefault ).MatchLabel (LabelKeyIsViolatingPDB , LabelValueViolatingPDB ).MinAvailable ("100%" ).Obj (),
255
+ st .MakePDB ().Name ("non-violating-pdb" ).Namespace (v1 .NamespaceDefault ).MatchLabel (LabelKeyIsViolatingPDB , LabelValueNonViolatingPDB ).MinAvailable ("0" ).DisruptionsAllowed (math .MaxInt32 ).Obj (),
256
+ },
257
+ nodes : []* v1.Node {
258
+ st .MakeNode ().Name ("node1" ).Capacity (onePodRes ).Obj (),
259
+ st .MakeNode ().Name ("node2" ).Capacity (onePodRes ).Obj (),
260
+ },
261
+ filteredNodesStatuses : framework .NewNodeToStatus (map [string ]* framework.Status {
262
+ "node1" : framework .NewStatus (framework .Unschedulable ),
263
+ "node2" : framework .NewStatus (framework .Unschedulable ),
264
+ }, framework .NewStatus (framework .UnschedulableAndUnresolvable )),
265
+ wantResult : framework .NewPostFilterResultWithNominatedNode ("node2" ),
266
+ wantStatus : framework .NewStatus (framework .Success ),
267
+ },
237
268
{
238
269
name : "preemption result filtered out by extenders" ,
239
270
pod : st .MakePod ().Name ("p" ).UID ("p" ).Namespace (v1 .NamespaceDefault ).Priority (highPriority ).Obj (),
@@ -365,6 +396,13 @@ func TestPostFilter(t *testing.T) {
365
396
for i := range tt .pods {
366
397
podInformer .GetStore ().Add (tt .pods [i ])
367
398
}
399
+ pdbInformer := informerFactory .Policy ().V1 ().PodDisruptionBudgets ().Informer ()
400
+ for i := range tt .pdbs {
401
+ if err := pdbInformer .GetStore ().Add (tt .pdbs [i ]); err != nil {
402
+ t .Fatal (err )
403
+ }
404
+ }
405
+
368
406
// Register NodeResourceFit as the Filter & PreFilter plugin.
369
407
registeredPlugins := []tf.RegisterPluginFunc {
370
408
tf .RegisterQueueSortPlugin (queuesort .Name , queuesort .New ),
0 commit comments