@@ -218,6 +218,7 @@ func TestEvictionIngorePDB(t *testing.T) {
218
218
podPhase api.PodPhase
219
219
podName string
220
220
expectedDeleteCount int
221
+ podTerminating bool
221
222
}{
222
223
{
223
224
name : "pdbs No disruptions allowed, pod pending, first delete conflict, pod still pending, pod deleted successfully" ,
@@ -287,6 +288,19 @@ func TestEvictionIngorePDB(t *testing.T) {
287
288
podName : "t5" ,
288
289
expectedDeleteCount : 1 ,
289
290
},
291
+ {
292
+ name : "matching pdbs with no disruptions allowed, pod terminating" ,
293
+ pdbs : []runtime.Object {& policyv1beta1.PodDisruptionBudget {
294
+ ObjectMeta : metav1.ObjectMeta {Name : "foo" , Namespace : "default" },
295
+ Spec : policyv1beta1.PodDisruptionBudgetSpec {Selector : & metav1.LabelSelector {MatchLabels : map [string ]string {"a" : "true" }}},
296
+ Status : policyv1beta1.PodDisruptionBudgetStatus {DisruptionsAllowed : 0 },
297
+ }},
298
+ eviction : & policy.Eviction {ObjectMeta : metav1.ObjectMeta {Name : "t6" , Namespace : "default" }, DeleteOptions : metav1 .NewDeleteOptions (300 )},
299
+ expectError : false ,
300
+ podName : "t6" ,
301
+ expectedDeleteCount : 1 ,
302
+ podTerminating : true ,
303
+ },
290
304
}
291
305
292
306
for _ , tc := range testcases {
@@ -304,6 +318,11 @@ func TestEvictionIngorePDB(t *testing.T) {
304
318
pod .Status .Phase = tc .podPhase
305
319
}
306
320
321
+ if tc .podTerminating {
322
+ currentTime := metav1 .Now ()
323
+ pod .ObjectMeta .DeletionTimestamp = & currentTime
324
+ }
325
+
307
326
client := fake .NewSimpleClientset (tc .pdbs ... )
308
327
evictionRest := newEvictionStorage (ms , client .PolicyV1beta1 ())
309
328
@@ -397,6 +416,10 @@ func (ms *mockStore) mutatorDeleteFunc(count int, options *metav1.DeleteOptions)
397
416
// Always return error for this pod
398
417
return nil , false , apierrors .NewConflict (resource ("tests" ), "2" , errors .New ("message" ))
399
418
}
419
+ if ms .pod .Name == "t6" {
420
+ // This pod has a deletionTimestamp and should not raise conflict on delete
421
+ return nil , true , nil
422
+ }
400
423
if count == 1 {
401
424
// This is a hack to ensure that some test pods don't change phase
402
425
// but do change resource version
0 commit comments