Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKS-2227: Fix deleting a PG might create multiple deletion tasks at the same time #164

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion pkg/service/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@
},
}

if _, err := svr.Session.VMPlacementGroup.DeleteVMPlacementGroup(deleteVMPlacementGroupParams); err != nil {
deleteVMPlacementGroupResp, err := svr.Session.VMPlacementGroup.DeleteVMPlacementGroup(deleteVMPlacementGroupParams)
if err != nil {

Check warning on line 951 in pkg/service/vm.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/vm.go#L950-L951

Added lines #L950 - L951 were not covered by tests
return nil, err
}

Expand All @@ -956,6 +957,25 @@
pgNames[i] = *getVMPlacementGroupsResp.Payload[i].Name
}

if len(deleteVMPlacementGroupResp.Payload) == 0 {
return pgNames, nil
}

Check warning on line 962 in pkg/service/vm.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/vm.go#L960-L962

Added lines #L960 - L962 were not covered by tests

// With consecutive calls to DeleteVMPlacementGroupsByNamePrefix (e.g. a short reconcile interval),
// Tower may create duplicate tasks for deleting placement groups.
// Wait for the first deletion task to complete or timeout,
// can increase the interval between calls to DeleteVMPlacementGroupsByNamePrefix
// to reduce the probability of duplicate deletion tasks.
taskID := *deleteVMPlacementGroupResp.Payload[0].TaskID
withLatestStatusTask, err := svr.WaitTask(ctx, taskID, config.WaitTaskTimeoutForPlacementGroupOperation, config.WaitTaskInterval)
if err != nil {
return pgNames, errors.Wrapf(err, "failed to wait for placement groups with name prefix %s deleting task to complete in %s: taskID %s", namePrefix, config.WaitTaskTimeoutForPlacementGroupOperation, taskID)
}

Check warning on line 973 in pkg/service/vm.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/vm.go#L969-L973

Added lines #L969 - L973 were not covered by tests

if *withLatestStatusTask.Status == models.TaskStatusFAILED {
return pgNames, errors.Errorf("failed to delete placement groups with name prefix %s in task %s", namePrefix, *withLatestStatusTask.ID)
}

Check warning on line 977 in pkg/service/vm.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/vm.go#L975-L977

Added lines #L975 - L977 were not covered by tests

return pgNames, nil
}

Expand Down