droplet: Refactor post-create polling code.#776
Merged
andrewsomething merged 3 commits intomainfrom Jan 14, 2022
Merged
Conversation
ChiefMateStarbuck
approved these changes
Jan 14, 2022
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR refactors the code used to poll a Droplet's status after the request to create it. #767 points out one issue with the existing implementation, but it also exposes another issue with it. So I've taken the opportunity to fix those and make the entire process more efficient.
It now first uses
waitForActionto ensure that the Droplet create action completes successfully. This allows us to fail fast in the case of a real error instead of continuing to poll the non-existent Droplet. Polling the action endpoint allows for an error to be reported while polling the droplet endpoint just 404s (which we retry on) if the create fails.The call to
waitForDropletAttributechecking for the Droplet'sstatusattribute to move fromnewtoactiveis still made after that. This is possibly unnecessary, but I've kept it to make sure we don't introduce any unexpected behavior changes. (I'm not 100% positive that the action completing is entirely equivalent to the Droplet becoming active.)It also removes the usage of
resourceDigitalOceanDropletReadindropletStateRefreshFuncin order to reduce the overall number of API calls made. Currently inmain, each pass throughnewDropletStateRefreshFuncactually callsclient.Droplets.Gettwice. The final call inresourceDigitalOceanDropletCreatetoresourceDigitalOceanDropletReadis also removed to cut another redundant API call.So while this now makes calls to both the actions and droplets endpoints to make sure the Droplet has been successfully created, it is still more efficient and reduces the overall number of API call made substantially.
Additionally, there are a number of unrelated fixes to the Droplet acceptance tests so that they all now pass. These failure seem to be the result of moving the tests from using legacy Droplet plans to new ones without updating the expected disk sizes.