@@ -184,6 +184,7 @@ var (
184184
185185func TestPrune (t * testing.T ) {
186186 tests := map [string ]struct {
187+ clusterObjs []* unstructured.Unstructured
187188 pruneObjs []* unstructured.Unstructured
188189 pruneFilters []filter.ValidationFilter
189190 options Options
@@ -193,13 +194,15 @@ func TestPrune(t *testing.T) {
193194 expectedAbandoned object.ObjMetadataSet
194195 }{
195196 "No pruned objects; no prune/delete events" : {
197+ clusterObjs : []* unstructured.Unstructured {},
196198 pruneObjs : []* unstructured.Unstructured {},
197199 options : defaultOptions ,
198200 expectedEvents : nil ,
199201 },
200202 "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 ,
203206 expectedEvents : []event.Event {
204207 {
205208 Type : event .PruneType ,
@@ -212,8 +215,9 @@ func TestPrune(t *testing.T) {
212215 },
213216 },
214217 "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 ,
217221 expectedEvents : []event.Event {
218222 {
219223 Type : event .PruneType ,
@@ -242,8 +246,9 @@ func TestPrune(t *testing.T) {
242246 },
243247 },
244248 "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 ,
247252 expectedEvents : []event.Event {
248253 {
249254 Type : event .DeleteType ,
@@ -256,8 +261,9 @@ func TestPrune(t *testing.T) {
256261 },
257262 },
258263 "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 ,
261267 expectedEvents : []event.Event {
262268 {
263269 Type : event .DeleteType ,
@@ -286,8 +292,9 @@ func TestPrune(t *testing.T) {
286292 },
287293 },
288294 "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 ,
291298 expectedEvents : []event.Event {
292299 {
293300 Type : event .PruneType ,
@@ -300,7 +307,8 @@ func TestPrune(t *testing.T) {
300307 },
301308 },
302309 "Server dry run still deleted event" : {
303- pruneObjs : []* unstructured.Unstructured {pod },
310+ clusterObjs : []* unstructured.Unstructured {pod },
311+ pruneObjs : []* unstructured.Unstructured {pod },
304312 options : Options {
305313 DryRunStrategy : common .DryRunServer ,
306314 PropagationPolicy : metav1 .DeletePropagationBackground ,
@@ -318,7 +326,8 @@ func TestPrune(t *testing.T) {
318326 },
319327 },
320328 "UID match means prune skipped" : {
321- pruneObjs : []* unstructured.Unstructured {pod },
329+ clusterObjs : []* unstructured.Unstructured {pod },
330+ pruneObjs : []* unstructured.Unstructured {pod },
322331 pruneFilters : []filter.ValidationFilter {
323332 filter.CurrentUIDFilter {
324333 // Add pod UID to set of current UIDs
@@ -344,7 +353,8 @@ func TestPrune(t *testing.T) {
344353 },
345354 },
346355 "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 },
348358 pruneFilters : []filter.ValidationFilter {
349359 filter.CurrentUIDFilter {
350360 // Add pod UID to set of current UIDs
@@ -378,6 +388,10 @@ func TestPrune(t *testing.T) {
378388 },
379389 },
380390 "Prevent delete annotation equals prune skipped" : {
391+ clusterObjs : []* unstructured.Unstructured {
392+ podDeletionPrevention ,
393+ testutil .Unstructured (t , pdbDeletePreventionManifest ),
394+ },
381395 pruneObjs : []* unstructured.Unstructured {
382396 podDeletionPrevention ,
383397 testutil .Unstructured (t , pdbDeletePreventionManifest ),
@@ -422,6 +436,10 @@ func TestPrune(t *testing.T) {
422436 },
423437 },
424438 "Prevent delete annotation equals delete skipped" : {
439+ clusterObjs : []* unstructured.Unstructured {
440+ podDeletionPrevention ,
441+ testutil .Unstructured (t , pdbDeletePreventionManifest ),
442+ },
425443 pruneObjs : []* unstructured.Unstructured {
426444 podDeletionPrevention ,
427445 testutil .Unstructured (t , pdbDeletePreventionManifest ),
@@ -466,6 +484,7 @@ func TestPrune(t *testing.T) {
466484 },
467485 },
468486 "Prevent delete annotation, one skipped, one pruned" : {
487+ clusterObjs : []* unstructured.Unstructured {podDeletionPrevention , pod },
469488 pruneObjs : []* unstructured.Unstructured {podDeletionPrevention , pod },
470489 pruneFilters : []filter.ValidationFilter {filter.PreventRemoveFilter {}},
471490 options : defaultOptions ,
@@ -500,7 +519,8 @@ func TestPrune(t *testing.T) {
500519 },
501520 },
502521 "Namespace prune skipped" : {
503- pruneObjs : []* unstructured.Unstructured {namespace },
522+ clusterObjs : []* unstructured.Unstructured {namespace },
523+ pruneObjs : []* unstructured.Unstructured {namespace },
504524 pruneFilters : []filter.ValidationFilter {
505525 filter.LocalNamespacesFilter {
506526 LocalNamespaces : sets .NewString (namespace .GetName ()),
@@ -524,19 +544,34 @@ func TestPrune(t *testing.T) {
524544 object .UnstructuredToObjMetadata (namespace ),
525545 },
526546 },
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+ },
527562 }
528563
529564 for name , tc := range tests {
530565 t .Run (name , func (t * testing.T ) {
531566 // 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 )
535570 }
536571 pruneIds := object .UnstructuredSetToObjMetadataSet (tc .pruneObjs )
537572 po := Pruner {
538573 InvClient : inventory .NewFakeClient (pruneIds ),
539- Client : fake .NewSimpleDynamicClient (scheme .Scheme , objs ... ),
574+ Client : fake .NewSimpleDynamicClient (scheme .Scheme , clusterObjs ... ),
540575 Mapper : testrestmapper .TestOnlyStaticRESTMapper (scheme .Scheme ,
541576 scheme .Scheme .PrioritizedVersionsAllGroups ()... ),
542577 }
0 commit comments