-
Notifications
You must be signed in to change notification settings - Fork 42
fix: Avoid error in organization delete operation if done just after creation #1542
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd12586
TODO revert - triggering CI run
AgustinBettati 754df38
retry delete request after 20 seconds if 500 Internal Server Error is…
AgustinBettati 1528c5a
extract into a function
AgustinBettati 518c582
add file from make build
AgustinBettati faa0bc2
adding log statement in case of retry
AgustinBettati 3f3d9af
fixing linting
AgustinBettati de14e1c
Merge remote-tracking branch 'origin/master' into CLOUDP-332705
AgustinBettati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,6 +221,33 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler | |
| return handleError(response, constants.DELETE, err) | ||
| } | ||
|
|
||
| currentModel.IsDeleted = util.Pointer(false) | ||
|
|
||
| responseMsg, progressEvent := runDelete(ctx, conn, currentModel) | ||
| if responseMsg.Error != nil { | ||
| // Retry once on transient server error, waiting 20 seconds before retrying request | ||
| // This covers case of contract tests which create and delete an org within seconds, encountering an error while deleting the org | ||
| if responseMsg.Response != nil && responseMsg.Response.StatusCode == http.StatusInternalServerError { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to add a log here |
||
| _, _ = logger.Warnf("Transient server error while deleting organization, retrying in 20 seconds") | ||
| time.Sleep(20 * time.Second) | ||
| responseMsg, progressEvent = runDelete(ctx, conn, currentModel) | ||
| } | ||
| } | ||
| if progressEvent != nil { | ||
| return *progressEvent, nil | ||
| } | ||
| if responseMsg.Error != nil { | ||
| return handleError(responseMsg.Response, constants.DELETE, responseMsg.Error) | ||
| } | ||
|
|
||
| return handler.ProgressEvent{ | ||
| OperationStatus: handler.Success, | ||
| Message: DeleteCompleted, | ||
| ResourceModel: nil}, nil | ||
| } | ||
|
|
||
| // Encapsulate the delete+wait logic so the same flow can be used on retry. | ||
|
AgustinBettati marked this conversation as resolved.
|
||
| func runDelete(ctx context.Context, conn *admin.APIClient, currentModel *Model) (*DeleteResponse, *handler.ProgressEvent) { | ||
| deleteRequest := conn.OrganizationsApi.DeleteOrg(ctx, *currentModel.OrgId) | ||
|
|
||
| // Since the Delete API is synchronous and takes more than 1 minute most of the time, | ||
|
|
@@ -234,31 +261,22 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler | |
| responseChan <- DeleteResponse{Error: err, Response: response} | ||
| }() | ||
|
|
||
| currentModel.IsDeleted = util.Pointer(false) | ||
| select { | ||
| case responseMsg := <-responseChan: | ||
| if responseMsg.Error != nil { | ||
| return handleError(responseMsg.Response, constants.DELETE, responseMsg.Error) | ||
| } | ||
|
|
||
| return &responseMsg, nil | ||
| case <-time.After(30 * time.Second): | ||
| // If the Delete is not completed in the above time, | ||
| // we return a progress event with inProgress status and callback context | ||
| return handler.ProgressEvent{ | ||
| return nil, &handler.ProgressEvent{ | ||
| OperationStatus: handler.InProgress, | ||
| Message: DeleteInProgress, | ||
| ResourceModel: currentModel, | ||
| CallbackDelaySeconds: CallBackSeconds, | ||
| CallbackContext: map[string]interface{}{ | ||
| constants.StateName: DeletingState, | ||
| }, | ||
| }, nil | ||
| } | ||
| } | ||
|
|
||
| return handler.ProgressEvent{ | ||
| OperationStatus: handler.Success, | ||
| Message: DeleteCompleted, | ||
| ResourceModel: nil}, nil | ||
| } | ||
|
|
||
| func deleteCallback(ctx context.Context, conn *admin.APIClient, currentModel *Model) (handler.ProgressEvent, error) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.