Skip to content

Commit 1c4eae9

Browse files
committed
fix: retain inventory for pruning failures
Prior to this change, the inventory always was deleted at the end of a Destroy event. This would occur even in the case of a pruning failure, resulting in the objects being removed from the inventory without being deleted. This change makes it so that the inventory is only deleted if all objects have been pruned.
1 parent 8609e42 commit 1c4eae9

18 files changed

+400
-208
lines changed

pkg/apply/destroyer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func TestDestroyerCancel(t *testing.T) {
292292
EventType: event.ActionGroupType,
293293
ActionGroupEvent: &testutil.ExpActionGroupEvent{
294294
Action: event.InventoryAction,
295-
GroupName: "delete-inventory-0",
295+
GroupName: "inventory-delete-or-update-0",
296296
Type: event.Started,
297297
},
298298
},
@@ -301,7 +301,7 @@ func TestDestroyerCancel(t *testing.T) {
301301
EventType: event.ActionGroupType,
302302
ActionGroupEvent: &testutil.ExpActionGroupEvent{
303303
Action: event.InventoryAction,
304-
GroupName: "delete-inventory-0",
304+
GroupName: "inventory-delete-or-update-0",
305305
Type: event.Finished,
306306
},
307307
},

pkg/apply/solver/solver.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,26 +211,22 @@ func (t *TaskQueueBuilder) Build(taskContext *taskrunner.TaskContext, o Options)
211211
}
212212
}
213213

214-
// TODO: add InvSetTask when Destroy=true to retain undeleted objects
215-
if !o.Destroy {
216-
klog.V(2).Infoln("adding inventory set task")
217-
prevInvIds, _ := t.InvClient.GetClusterObjs(t.invInfo)
218-
tasks = append(tasks, &task.InvSetTask{
219-
TaskName: "inventory-set-0",
220-
InvClient: t.InvClient,
221-
InvInfo: t.invInfo,
222-
PrevInventory: prevInvIds,
223-
DryRun: o.DryRunStrategy,
224-
})
214+
prevInvIds, _ := t.InvClient.GetClusterObjs(t.invInfo)
215+
klog.V(2).Infoln("adding delete/update inventory task")
216+
var taskName string
217+
if o.Destroy {
218+
taskName = "inventory-delete-or-update-0"
225219
} else {
226-
klog.V(2).Infoln("adding delete inventory task")
227-
tasks = append(tasks, &task.DeleteInvTask{
228-
TaskName: "delete-inventory-0",
229-
InvClient: t.InvClient,
230-
InvInfo: t.invInfo,
231-
DryRun: o.DryRunStrategy,
232-
})
220+
taskName = "inventory-set-0"
233221
}
222+
tasks = append(tasks, &task.DeleteOrUpdateInvTask{
223+
TaskName: taskName,
224+
InvClient: t.InvClient,
225+
InvInfo: t.invInfo,
226+
PrevInventory: prevInvIds,
227+
DryRun: o.DryRunStrategy,
228+
Destroy: o.Destroy,
229+
})
234230

235231
return &TaskQueue{tasks: tasks}
236232
}

pkg/apply/solver/solver_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
149149
InvInfo: invInfo,
150150
Objects: object.UnstructuredSet{},
151151
},
152-
&task.InvSetTask{
152+
&task.DeleteOrUpdateInvTask{
153153
TaskName: "inventory-set-0",
154154
InvClient: &inventory.FakeClient{},
155155
InvInfo: invInfo,
@@ -183,7 +183,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
183183
},
184184
Condition: taskrunner.AllCurrent,
185185
},
186-
&task.InvSetTask{
186+
&task.DeleteOrUpdateInvTask{
187187
TaskName: "inventory-set-0",
188188
InvClient: &inventory.FakeClient{},
189189
InvInfo: invInfo,
@@ -234,7 +234,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
234234
},
235235
Condition: taskrunner.AllCurrent,
236236
},
237-
&task.InvSetTask{
237+
&task.DeleteOrUpdateInvTask{
238238
TaskName: "inventory-set-0",
239239
InvClient: &inventory.FakeClient{},
240240
InvInfo: invInfo,
@@ -298,7 +298,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
298298
Condition: taskrunner.AllCurrent,
299299
Timeout: 1 * time.Minute,
300300
},
301-
&task.InvSetTask{
301+
&task.DeleteOrUpdateInvTask{
302302
TaskName: "inventory-set-0",
303303
InvClient: &inventory.FakeClient{},
304304
InvInfo: invInfo,
@@ -356,7 +356,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
356356
},
357357
DryRunStrategy: common.DryRunClient,
358358
},
359-
&task.InvSetTask{
359+
&task.DeleteOrUpdateInvTask{
360360
TaskName: "inventory-set-0",
361361
InvClient: &inventory.FakeClient{},
362362
InvInfo: invInfo,
@@ -415,7 +415,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
415415
},
416416
DryRunStrategy: common.DryRunServer,
417417
},
418-
&task.InvSetTask{
418+
&task.DeleteOrUpdateInvTask{
419419
TaskName: "inventory-set-0",
420420
InvClient: &inventory.FakeClient{},
421421
InvInfo: invInfo,
@@ -492,7 +492,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
492492
},
493493
Condition: taskrunner.AllCurrent,
494494
},
495-
&task.InvSetTask{
495+
&task.DeleteOrUpdateInvTask{
496496
TaskName: "inventory-set-0",
497497
InvClient: &inventory.FakeClient{},
498498
InvInfo: invInfo,
@@ -567,7 +567,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
567567
},
568568
DryRunStrategy: common.DryRunClient,
569569
},
570-
&task.InvSetTask{
570+
&task.DeleteOrUpdateInvTask{
571571
TaskName: "inventory-set-0",
572572
InvClient: &inventory.FakeClient{},
573573
InvInfo: invInfo,
@@ -653,7 +653,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
653653
},
654654
Condition: taskrunner.AllCurrent,
655655
},
656-
&task.InvSetTask{
656+
&task.DeleteOrUpdateInvTask{
657657
TaskName: "inventory-set-0",
658658
InvClient: &inventory.FakeClient{},
659659
InvInfo: invInfo,
@@ -737,7 +737,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
737737
},
738738
Condition: taskrunner.AllCurrent,
739739
},
740-
&task.InvSetTask{
740+
&task.DeleteOrUpdateInvTask{
741741
TaskName: "inventory-set-0",
742742
InvClient: &inventory.FakeClient{},
743743
InvInfo: invInfo,
@@ -862,7 +862,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
862862
InvInfo: invInfo,
863863
Objects: object.UnstructuredSet{},
864864
},
865-
&task.InvSetTask{
865+
&task.DeleteOrUpdateInvTask{
866866
TaskName: "inventory-set-0",
867867
InvClient: &inventory.FakeClient{},
868868
InvInfo: invInfo,
@@ -895,7 +895,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
895895
},
896896
Condition: taskrunner.AllNotFound,
897897
},
898-
&task.InvSetTask{
898+
&task.DeleteOrUpdateInvTask{
899899
TaskName: "inventory-set-0",
900900
InvClient: &inventory.FakeClient{},
901901
InvInfo: invInfo,
@@ -943,7 +943,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
943943
},
944944
Condition: taskrunner.AllNotFound,
945945
},
946-
&task.InvSetTask{
946+
&task.DeleteOrUpdateInvTask{
947947
TaskName: "inventory-set-0",
948948
InvClient: &inventory.FakeClient{},
949949
InvInfo: invInfo,
@@ -1014,7 +1014,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
10141014
},
10151015
Condition: taskrunner.AllNotFound,
10161016
},
1017-
&task.InvSetTask{
1017+
&task.DeleteOrUpdateInvTask{
10181018
TaskName: "inventory-set-0",
10191019
InvClient: &inventory.FakeClient{},
10201020
InvInfo: invInfo,
@@ -1072,7 +1072,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
10721072
Condition: taskrunner.AllNotFound,
10731073
Timeout: 3 * time.Minute,
10741074
},
1075-
&task.InvSetTask{
1075+
&task.DeleteOrUpdateInvTask{
10761076
TaskName: "inventory-set-0",
10771077
InvClient: &inventory.FakeClient{},
10781078
InvInfo: invInfo,
@@ -1119,7 +1119,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
11191119
},
11201120
DryRunStrategy: common.DryRunServer,
11211121
},
1122-
&task.InvSetTask{
1122+
&task.DeleteOrUpdateInvTask{
11231123
TaskName: "inventory-set-0",
11241124
InvClient: &inventory.FakeClient{},
11251125
InvInfo: invInfo,
@@ -1192,7 +1192,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
11921192
},
11931193
Condition: taskrunner.AllNotFound,
11941194
},
1195-
&task.InvSetTask{
1195+
&task.DeleteOrUpdateInvTask{
11961196
TaskName: "inventory-set-0",
11971197
InvClient: &inventory.FakeClient{},
11981198
InvInfo: invInfo,
@@ -1264,7 +1264,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
12641264
},
12651265
DryRunStrategy: common.DryRunClient,
12661266
},
1267-
&task.InvSetTask{
1267+
&task.DeleteOrUpdateInvTask{
12681268
TaskName: "inventory-set-0",
12691269
InvClient: &inventory.FakeClient{},
12701270
InvInfo: invInfo,
@@ -1345,7 +1345,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
13451345
},
13461346
Condition: taskrunner.AllNotFound,
13471347
},
1348-
&task.InvSetTask{
1348+
&task.DeleteOrUpdateInvTask{
13491349
TaskName: "inventory-set-0",
13501350
InvClient: &inventory.FakeClient{},
13511351
InvInfo: invInfo,
@@ -1439,7 +1439,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
14391439
taskrunner.AllCurrent, 1*time.Second,
14401440
testutil.NewFakeRESTMapper(),
14411441
),
1442-
&task.InvSetTask{
1442+
&task.DeleteOrUpdateInvTask{
14431443
TaskName: "inventory-set-0",
14441444
InvClient: &inventory.FakeClient{},
14451445
InvInfo: invInfo,
@@ -1574,7 +1574,7 @@ func TestTaskQueueBuilder_ApplyPruneBuild(t *testing.T) {
15741574
},
15751575
Condition: taskrunner.AllNotFound,
15761576
},
1577-
&task.InvSetTask{
1577+
&task.DeleteOrUpdateInvTask{
15781578
TaskName: "inventory-set-0",
15791579
InvClient: &inventory.FakeClient{},
15801580
InvInfo: invInfo,
@@ -1635,7 +1635,7 @@ func TestTaskQueueBuilder_ApplyPruneBuild(t *testing.T) {
16351635
},
16361636
Condition: taskrunner.AllCurrent,
16371637
},
1638-
&task.InvSetTask{
1638+
&task.DeleteOrUpdateInvTask{
16391639
TaskName: "inventory-set-0",
16401640
InvClient: &inventory.FakeClient{},
16411641
InvInfo: invInfo,
@@ -1709,7 +1709,7 @@ func TestTaskQueueBuilder_ApplyPruneBuild(t *testing.T) {
17091709
},
17101710
Condition: taskrunner.AllNotFound,
17111711
},
1712-
&task.InvSetTask{
1712+
&task.DeleteOrUpdateInvTask{
17131713
TaskName: "inventory-set-0",
17141714
InvClient: &inventory.FakeClient{},
17151715
InvInfo: invInfo,
@@ -1789,7 +1789,7 @@ func TestTaskQueueBuilder_ApplyPruneBuild(t *testing.T) {
17891789
},
17901790
Condition: taskrunner.AllNotFound,
17911791
},
1792-
&task.InvSetTask{
1792+
&task.DeleteOrUpdateInvTask{
17931793
TaskName: "inventory-set-0",
17941794
InvClient: &inventory.FakeClient{},
17951795
InvInfo: invInfo,

pkg/apply/task/delete_inv_task.go

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)