@@ -184,6 +184,7 @@ var (
184
184
185
185
func TestPrune (t * testing.T ) {
186
186
tests := map [string ]struct {
187
+ clusterObjs []* unstructured.Unstructured
187
188
pruneObjs []* unstructured.Unstructured
188
189
pruneFilters []filter.ValidationFilter
189
190
options Options
@@ -193,13 +194,15 @@ func TestPrune(t *testing.T) {
193
194
expectedAbandoned object.ObjMetadataSet
194
195
}{
195
196
"No pruned objects; no prune/delete events" : {
197
+ clusterObjs : []* unstructured.Unstructured {},
196
198
pruneObjs : []* unstructured.Unstructured {},
197
199
options : defaultOptions ,
198
200
expectedEvents : nil ,
199
201
},
200
202
"One successfully pruned object" : {
201
- pruneObjs : []* unstructured.Unstructured {pod },
202
- options : defaultOptions ,
203
+ clusterObjs : []* unstructured.Unstructured {pod },
204
+ pruneObjs : []* unstructured.Unstructured {pod },
205
+ options : defaultOptions ,
203
206
expectedEvents : []event.Event {
204
207
{
205
208
Type : event .PruneType ,
@@ -212,8 +215,9 @@ func TestPrune(t *testing.T) {
212
215
},
213
216
},
214
217
"Multiple successfully pruned object" : {
215
- pruneObjs : []* unstructured.Unstructured {pod , pdb , namespace },
216
- options : defaultOptions ,
218
+ clusterObjs : []* unstructured.Unstructured {pod , pdb , namespace },
219
+ pruneObjs : []* unstructured.Unstructured {pod , pdb , namespace },
220
+ options : defaultOptions ,
217
221
expectedEvents : []event.Event {
218
222
{
219
223
Type : event .PruneType ,
@@ -242,8 +246,9 @@ func TestPrune(t *testing.T) {
242
246
},
243
247
},
244
248
"One successfully deleted object" : {
245
- pruneObjs : []* unstructured.Unstructured {pod },
246
- options : defaultOptionsDestroy ,
249
+ clusterObjs : []* unstructured.Unstructured {pod },
250
+ pruneObjs : []* unstructured.Unstructured {pod },
251
+ options : defaultOptionsDestroy ,
247
252
expectedEvents : []event.Event {
248
253
{
249
254
Type : event .DeleteType ,
@@ -256,8 +261,9 @@ func TestPrune(t *testing.T) {
256
261
},
257
262
},
258
263
"Multiple successfully deleted objects" : {
259
- pruneObjs : []* unstructured.Unstructured {pod , pdb , namespace },
260
- options : defaultOptionsDestroy ,
264
+ clusterObjs : []* unstructured.Unstructured {pod , pdb , namespace },
265
+ pruneObjs : []* unstructured.Unstructured {pod , pdb , namespace },
266
+ options : defaultOptionsDestroy ,
261
267
expectedEvents : []event.Event {
262
268
{
263
269
Type : event .DeleteType ,
@@ -286,8 +292,9 @@ func TestPrune(t *testing.T) {
286
292
},
287
293
},
288
294
"Client dry run still pruned event" : {
289
- pruneObjs : []* unstructured.Unstructured {pod },
290
- options : clientDryRunOptions ,
295
+ clusterObjs : []* unstructured.Unstructured {pod },
296
+ pruneObjs : []* unstructured.Unstructured {pod },
297
+ options : clientDryRunOptions ,
291
298
expectedEvents : []event.Event {
292
299
{
293
300
Type : event .PruneType ,
@@ -300,7 +307,8 @@ func TestPrune(t *testing.T) {
300
307
},
301
308
},
302
309
"Server dry run still deleted event" : {
303
- pruneObjs : []* unstructured.Unstructured {pod },
310
+ clusterObjs : []* unstructured.Unstructured {pod },
311
+ pruneObjs : []* unstructured.Unstructured {pod },
304
312
options : Options {
305
313
DryRunStrategy : common .DryRunServer ,
306
314
PropagationPolicy : metav1 .DeletePropagationBackground ,
@@ -318,7 +326,8 @@ func TestPrune(t *testing.T) {
318
326
},
319
327
},
320
328
"UID match means prune skipped" : {
321
- pruneObjs : []* unstructured.Unstructured {pod },
329
+ clusterObjs : []* unstructured.Unstructured {pod },
330
+ pruneObjs : []* unstructured.Unstructured {pod },
322
331
pruneFilters : []filter.ValidationFilter {
323
332
filter.CurrentUIDFilter {
324
333
// Add pod UID to set of current UIDs
@@ -344,7 +353,8 @@ func TestPrune(t *testing.T) {
344
353
},
345
354
},
346
355
"UID match for only one object one pruned, one skipped" : {
347
- pruneObjs : []* unstructured.Unstructured {pod , pdb },
356
+ clusterObjs : []* unstructured.Unstructured {pod , pdb },
357
+ pruneObjs : []* unstructured.Unstructured {pod , pdb },
348
358
pruneFilters : []filter.ValidationFilter {
349
359
filter.CurrentUIDFilter {
350
360
// Add pod UID to set of current UIDs
@@ -378,6 +388,10 @@ func TestPrune(t *testing.T) {
378
388
},
379
389
},
380
390
"Prevent delete annotation equals prune skipped" : {
391
+ clusterObjs : []* unstructured.Unstructured {
392
+ podDeletionPrevention ,
393
+ testutil .Unstructured (t , pdbDeletePreventionManifest ),
394
+ },
381
395
pruneObjs : []* unstructured.Unstructured {
382
396
podDeletionPrevention ,
383
397
testutil .Unstructured (t , pdbDeletePreventionManifest ),
@@ -422,6 +436,10 @@ func TestPrune(t *testing.T) {
422
436
},
423
437
},
424
438
"Prevent delete annotation equals delete skipped" : {
439
+ clusterObjs : []* unstructured.Unstructured {
440
+ podDeletionPrevention ,
441
+ testutil .Unstructured (t , pdbDeletePreventionManifest ),
442
+ },
425
443
pruneObjs : []* unstructured.Unstructured {
426
444
podDeletionPrevention ,
427
445
testutil .Unstructured (t , pdbDeletePreventionManifest ),
@@ -466,6 +484,7 @@ func TestPrune(t *testing.T) {
466
484
},
467
485
},
468
486
"Prevent delete annotation, one skipped, one pruned" : {
487
+ clusterObjs : []* unstructured.Unstructured {podDeletionPrevention , pod },
469
488
pruneObjs : []* unstructured.Unstructured {podDeletionPrevention , pod },
470
489
pruneFilters : []filter.ValidationFilter {filter.PreventRemoveFilter {}},
471
490
options : defaultOptions ,
@@ -500,7 +519,8 @@ func TestPrune(t *testing.T) {
500
519
},
501
520
},
502
521
"Namespace prune skipped" : {
503
- pruneObjs : []* unstructured.Unstructured {namespace },
522
+ clusterObjs : []* unstructured.Unstructured {namespace },
523
+ pruneObjs : []* unstructured.Unstructured {namespace },
504
524
pruneFilters : []filter.ValidationFilter {
505
525
filter.LocalNamespacesFilter {
506
526
LocalNamespaces : sets .NewString (namespace .GetName ()),
@@ -524,19 +544,34 @@ func TestPrune(t *testing.T) {
524
544
object .UnstructuredToObjMetadata (namespace ),
525
545
},
526
546
},
547
+ "Deletion of already deleted object" : {
548
+ clusterObjs : []* unstructured.Unstructured {},
549
+ pruneObjs : []* unstructured.Unstructured {pod },
550
+ options : defaultOptionsDestroy ,
551
+ expectedEvents : []event.Event {
552
+ {
553
+ Type : event .DeleteType ,
554
+ DeleteEvent : event.DeleteEvent {
555
+ Identifier : object .UnstructuredToObjMetadata (pod ),
556
+ Status : event .DeleteSuccessful ,
557
+ Object : pod ,
558
+ },
559
+ },
560
+ },
561
+ },
527
562
}
528
563
529
564
for name , tc := range tests {
530
565
t .Run (name , func (t * testing.T ) {
531
566
// Set up the fake dynamic client to recognize all objects, and the RESTMapper.
532
- objs := make ([]runtime.Object , 0 , len (tc .pruneObjs ))
533
- for _ , obj := range tc .pruneObjs {
534
- objs = append (objs , obj )
567
+ clusterObjs := make ([]runtime.Object , 0 , len (tc .clusterObjs ))
568
+ for _ , obj := range tc .clusterObjs {
569
+ clusterObjs = append (clusterObjs , obj )
535
570
}
536
571
pruneIds := object .UnstructuredSetToObjMetadataSet (tc .pruneObjs )
537
572
po := Pruner {
538
573
InvClient : inventory .NewFakeClient (pruneIds ),
539
- Client : fake .NewSimpleDynamicClient (scheme .Scheme , objs ... ),
574
+ Client : fake .NewSimpleDynamicClient (scheme .Scheme , clusterObjs ... ),
540
575
Mapper : testrestmapper .TestOnlyStaticRESTMapper (scheme .Scheme ,
541
576
scheme .Scheme .PrioritizedVersionsAllGroups ()... ),
542
577
}
0 commit comments