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

fix(vm): fixed startup / shutdown behaviour on HA clusters #508

Merged
merged 7 commits into from
Aug 21, 2023

Conversation

tseeker
Copy link
Contributor

@tseeker tseeker commented Aug 20, 2023

When a Proxmox cluster receives a shutdown or startup command for a VM that is declared as a HA resource, it doesn't honour the request immediately. Instead the API call returns and the state changes later, at the HA manager's discretion. Because of that, the plugin could end up trying to effect inappropriate changes on a VM that wasn't in the expected state.

This PR adds a wait loop after both startup and shutdown commands in order to ensure that the state is what we expect it to be.

Contributor's Note

Please mark the following items with an [x] if they apply to your PR.
Leave the [ ] if they are not applicable, or if you have not completed the item.

  • I have added / updated documentation in /docs for any user-facing features or additions.
  • I have added / updated templates in /examples for any new or updated resources / data sources.
  • I have ran make examples to verify that the change works as expected.

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #507

Due to how a Proxmox cluster reacts to a VM shutdown command when
running in HA mode, the VM might still be running when the shutdown API
calls returns. This commit adds a loop that actively waits for the VM's
status to change to "stopped" (while also accounting for the shutdown
timeout) after the call's return.
…cluster

This commit forces the plugin to wait for a VM to actually run after
requesting it to be started. This avoids problems with Proxmox's High
Availability mode, where a start request may not be immediately honoured
by the cluster.
@bpg
Copy link
Owner

bpg commented Aug 20, 2023

@all-contributors please add @tseeker for bug, tests

@allcontributors
Copy link
Contributor

@bpg

I've put up a pull request to add @tseeker! 🎉

// Shutdown the VM.
// Wait until a VM reaches the desired state. An error is returned if the VM doesn't reach the
// desired state within the given timeout.
func vmWaitState(ctx context.Context, vmAPI *vms.Client, state string, timeout int) diag.Diagnostics {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably reuse this one?

func (c *Client) WaitForVMState(ctx context.Context, state string, timeout int, delay int) error {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I hadn't seen it. Thanks for catching that.

Copy link
Owner

@bpg bpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use the existing function as per my comment above.

LGTM! 🚀

@bpg bpg merged commit 148a9e0 into bpg:main Aug 21, 2023
10 of 11 checks passed
@ghost ghost mentioned this pull request Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing a disk's datastore when HA is enabled causes various problems
2 participants