Skip to content

Commit

Permalink
Merge pull request #622 from sdowell/fix-partial-destroy
Browse files Browse the repository at this point in the history
fix: retain inventory for pruning fail/skip
  • Loading branch information
k8s-ci-robot authored Jul 24, 2023
2 parents 8609e42 + 1c4eae9 commit 833d70f
Show file tree
Hide file tree
Showing 18 changed files with 400 additions and 208 deletions.
4 changes: 2 additions & 2 deletions pkg/apply/destroyer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func TestDestroyerCancel(t *testing.T) {
EventType: event.ActionGroupType,
ActionGroupEvent: &testutil.ExpActionGroupEvent{
Action: event.InventoryAction,
GroupName: "delete-inventory-0",
GroupName: "inventory-delete-or-update-0",
Type: event.Started,
},
},
Expand All @@ -301,7 +301,7 @@ func TestDestroyerCancel(t *testing.T) {
EventType: event.ActionGroupType,
ActionGroupEvent: &testutil.ExpActionGroupEvent{
Action: event.InventoryAction,
GroupName: "delete-inventory-0",
GroupName: "inventory-delete-or-update-0",
Type: event.Finished,
},
},
Expand Down
32 changes: 14 additions & 18 deletions pkg/apply/solver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,22 @@ func (t *TaskQueueBuilder) Build(taskContext *taskrunner.TaskContext, o Options)
}
}

// TODO: add InvSetTask when Destroy=true to retain undeleted objects
if !o.Destroy {
klog.V(2).Infoln("adding inventory set task")
prevInvIds, _ := t.InvClient.GetClusterObjs(t.invInfo)
tasks = append(tasks, &task.InvSetTask{
TaskName: "inventory-set-0",
InvClient: t.InvClient,
InvInfo: t.invInfo,
PrevInventory: prevInvIds,
DryRun: o.DryRunStrategy,
})
prevInvIds, _ := t.InvClient.GetClusterObjs(t.invInfo)
klog.V(2).Infoln("adding delete/update inventory task")
var taskName string
if o.Destroy {
taskName = "inventory-delete-or-update-0"
} else {
klog.V(2).Infoln("adding delete inventory task")
tasks = append(tasks, &task.DeleteInvTask{
TaskName: "delete-inventory-0",
InvClient: t.InvClient,
InvInfo: t.invInfo,
DryRun: o.DryRunStrategy,
})
taskName = "inventory-set-0"
}
tasks = append(tasks, &task.DeleteOrUpdateInvTask{
TaskName: taskName,
InvClient: t.InvClient,
InvInfo: t.invInfo,
PrevInventory: prevInvIds,
DryRun: o.DryRunStrategy,
Destroy: o.Destroy,
})

return &TaskQueue{tasks: tasks}
}
Expand Down
48 changes: 24 additions & 24 deletions pkg/apply/solver/solver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
InvInfo: invInfo,
Objects: object.UnstructuredSet{},
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
},
Condition: taskrunner.AllCurrent,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
},
Condition: taskrunner.AllCurrent,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
Condition: taskrunner.AllCurrent,
Timeout: 1 * time.Minute,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
},
DryRunStrategy: common.DryRunClient,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
},
DryRunStrategy: common.DryRunServer,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
},
Condition: taskrunner.AllCurrent,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -567,7 +567,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
},
DryRunStrategy: common.DryRunClient,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -653,7 +653,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
},
Condition: taskrunner.AllCurrent,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -737,7 +737,7 @@ func TestTaskQueueBuilder_ApplyBuild(t *testing.T) {
},
Condition: taskrunner.AllCurrent,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -862,7 +862,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
InvInfo: invInfo,
Objects: object.UnstructuredSet{},
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -895,7 +895,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
},
Condition: taskrunner.AllNotFound,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -943,7 +943,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
},
Condition: taskrunner.AllNotFound,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
},
Condition: taskrunner.AllNotFound,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1072,7 +1072,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
Condition: taskrunner.AllNotFound,
Timeout: 3 * time.Minute,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1119,7 +1119,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
},
DryRunStrategy: common.DryRunServer,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1192,7 +1192,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
},
Condition: taskrunner.AllNotFound,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1264,7 +1264,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
},
DryRunStrategy: common.DryRunClient,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1345,7 +1345,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
},
Condition: taskrunner.AllNotFound,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1439,7 +1439,7 @@ func TestTaskQueueBuilder_PruneBuild(t *testing.T) {
taskrunner.AllCurrent, 1*time.Second,
testutil.NewFakeRESTMapper(),
),
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1574,7 +1574,7 @@ func TestTaskQueueBuilder_ApplyPruneBuild(t *testing.T) {
},
Condition: taskrunner.AllNotFound,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1635,7 +1635,7 @@ func TestTaskQueueBuilder_ApplyPruneBuild(t *testing.T) {
},
Condition: taskrunner.AllCurrent,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1709,7 +1709,7 @@ func TestTaskQueueBuilder_ApplyPruneBuild(t *testing.T) {
},
Condition: taskrunner.AllNotFound,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down Expand Up @@ -1789,7 +1789,7 @@ func TestTaskQueueBuilder_ApplyPruneBuild(t *testing.T) {
},
Condition: taskrunner.AllNotFound,
},
&task.InvSetTask{
&task.DeleteOrUpdateInvTask{
TaskName: "inventory-set-0",
InvClient: &inventory.FakeClient{},
InvInfo: invInfo,
Expand Down
57 changes: 0 additions & 57 deletions pkg/apply/task/delete_inv_task.go

This file was deleted.

Loading

0 comments on commit 833d70f

Please sign in to comment.