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

feat(vm): add support for migration when the node name is modified #501

Merged
merged 3 commits into from
Aug 19, 2023

Conversation

tseeker
Copy link
Contributor

@tseeker tseeker commented Aug 17, 2023

  • Added a migrate VM flag which changes the provider's behaviour when the VM's node_name is updated. If true, the VM will be migrated to the specified node instead of being re-created.

  • Added a timeout_migrate setting to control the timeout for VM migration.

  • Fixed a bug in the API's migration data structure that prevented the online migration flag to be set.

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 #499

  * Added a `migrate` VM flag which changes the provider's behaviour
    when the VM's `node_name` is updated. If `true`, the VM will be
    migrated to the specified node instead of being re-created.

  * Added a `timeout_migrate` setting to control the timeout for VM
    migration.

  * Fixed a bug in the API's migration data structure that prevented
    the online migration flag to be set.
@tseeker
Copy link
Contributor Author

tseeker commented Aug 17, 2023

That lint failure (which also occurred on my workstation, but I wanted to be sure) doesn't have anything to do with the code I added, yet it doesn't happen in the main branch. Weirder yet, it doesn't look like the section of code it happens on has been touched recently.

Not sure if I should fix it in this PR, since doing so kind of mixes concerns. On the other hand, well, the linter fails.

Edit: applying the patch below would solve the problem:

diff --git a/proxmoxtf/resource/vm.go b/proxmoxtf/resource/vm.go
index 6a2a71a..893f666 100644
--- a/proxmoxtf/resource/vm.go
+++ b/proxmoxtf/resource/vm.go
@@ -3908,7 +3908,6 @@ func vmReadCustom(
 
        currentPCIList := d.Get(mkResourceVirtualEnvironmentVMHostPCI).([]interface{})
        pciMap := map[string]interface{}{}
-       var orderedPCIList []interface{}
 
        pciDevices := getPCIInfo(vmConfig, d)
        for pi, pp := range pciDevices {
@@ -3960,8 +3959,9 @@ func vmReadCustom(
        }
        sort.Strings(keyList)
 
-       for _, k := range keyList {
-               orderedPCIList = append(orderedPCIList, pciMap[k])
+       orderedPCIList := make([]interface{}, len(keyList))
+       for i, k := range keyList {
+               orderedPCIList[i] = pciMap[k]
        }
 
        if len(clone) > 0 {

tseeker added a commit to tseeker/terraform-provider-proxmox that referenced this pull request Aug 18, 2023
  * This commit fixes a linter error that somehow doesn't manifest
    unless some other, unrelated changes trigger it (see bpg#501 and
    bpg#505).

  * In addition it fixes a similar issue that had so far gone undetected
    by the linter.

  * Refactored the code in question into a function, since it was mostly
    duplicated.

  * Simplified a pair of conditionals that had the same code in both
    branches.
@tseeker tseeker mentioned this pull request Aug 18, 2023
3 tasks
bpg pushed a commit that referenced this pull request Aug 19, 2023
fix: linter error in ambush

  * This commit fixes a linter error that somehow doesn't manifest
    unless some other, unrelated changes trigger it (see #501 and
    #505).

  * In addition it fixes a similar issue that had so far gone undetected
    by the linter.

  * Refactored the code in question into a function, since it was mostly
    duplicated.

  * Simplified a pair of conditionals that had the same code in both
    branches.
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.

This is a really useful feature, thanks for contributing @tseeker!

LGTM! 🚀

@@ -1367,6 +1376,12 @@ func VM() *schema.Resource {
Optional: true,
Default: dvResourceVirtualEnvironmentVMTimeoutMoveDisk,
},
mkResourceVirtualEnvironmentVMTimeoutMigrate: {
Type: schema.TypeInt,
Description: "MoveDisk timeout",
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like the descrition was not updated :)

@bpg bpg merged commit a285360 into bpg:main Aug 19, 2023
12 checks passed
@ghost ghost mentioned this pull request Aug 19, 2023
@bpg bpg changed the title feat(vm): support for migration when the node name is modified feat(vm): add support for migration when the node name is modified Aug 19, 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.

Ability to migrate VMs
2 participants