Skip to content

Conversation

@Vaneixus
Copy link
Contributor

@Vaneixus Vaneixus commented Sep 7, 2025

Contributor's Note

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

Proof of Work

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 #0000 | Relates #0000

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Vaneixus, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a limitation in updating virtual machine boot disks by implementing a more robust mechanism for handling disk import operations. It ensures that necessary VM state transitions, such as shutdowns and reboots, are correctly orchestrated when disk configurations are modified, particularly for bootable volumes. The changes improve the reliability and functionality of disk management within the system.

Highlights

  • Boot Disk Update Restoration: The pull request restores the ability to update boot disks by correctly handling the ImportFrom parameter. Previously, ImportFrom was not sent for existing disks due to issues with re-importing boot disks, but now it is conditionally sent, triggering a necessary VM shutdown and reboot.
  • VM State Management for Disk Updates: The VM update process has been refined to properly manage the virtual machine's state during disk updates. A new shutdownBeforeUpdate flag is introduced to ensure the VM is gracefully shut down before applying disk changes that require it, and then restarted if it was originally running.
  • Function Signature Update: The Update function in proxmoxtf/resource/vm/disk/disk.go now returns an additional boolean value, shutdownBeforeUpdate, to indicate whether a VM shutdown is required before applying disk changes. This change is propagated to calling functions and tests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Vaneixus
Copy link
Contributor Author

Vaneixus commented Sep 7, 2025

This is currently untested. but the end goal is restoring the updating of disks already in vm via import-from. it should work for all other disks, but the boot disk needs the vm to be offline before it gets updated.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to enable updating a boot disk, which involves re-importing it. The changes in proxmoxtf/resource/vm/disk/disk.go correctly identify that this operation requires the VM to be shut down. However, the implementation in proxmoxtf/resource/vm/vm.go has a flaw: while it correctly shuts down the VM for the update, it fails to restart it afterward, even if the VM is configured to be running. This leaves the resource in an inconsistent state. My review includes a critical fix to ensure the VM is restarted when required, restoring it to its configured state after the update.

@Vaneixus
Copy link
Contributor Author

Vaneixus commented Sep 7, 2025

I might need to add another parameter to identify boot disks to the update disk function.

Vaneixus and others added 3 commits September 7, 2025 03:30
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Marco Attia <[email protected]>
@Vaneixus Vaneixus force-pushed the Update_Disk_Via_Import branch from 963342a to 7d32487 Compare September 7, 2025 03:31
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.

Hey @Vaneixus 👋🏼!

Thank you for looking into that, and contributing the fix, but I have a few questions.

Comment on lines +627 to +633
if disk.ImportFrom != nil && *disk.ImportFrom != "" {
rebootRequired = true
shutdownBeforeUpdate = true
tmp.DatastoreID = disk.DatastoreID
tmp.ImportFrom = disk.ImportFrom
tmp.Size = disk.Size
}
Copy link
Owner

Choose a reason for hiding this comment

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

this part was specifically removed here
so I think this change will break the VM update scenario, when VM has an imported disk.

What was the reason for adding this back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello again @bpg, the reason this was re-added was that the boot disk cannot be changed while the vm is running, you can only change it while it isn't, at least that's what I remember being the case back when I opened the first PR. This PR is currently untested. I just opened it as to show my progress. I should have probably put it as a draft. It's also why I move the start-up/shutdown code, I probably have to change that part again. But basically, the whole idea is to shut down the vm to allow the boot disk to be changed. I just haven't had the opportunity to test this again. I will be working again on this PR on the weekend.

Comment on lines 5769 to 5772
e = vmAPI.UpdateVM(ctx, updateBody)
if e != nil {
return diag.FromErr(e)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry, I didn't quite get the reason for moving vmUpdate after vmStart / vmShutdown. This will affect ability to start / stop VM buy updating started=true|false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's untested this is a very much an incomplete code change, I need to switch this to a draft, I just forgot to d it.

@bpg bpg added the ⌛ pending author's response Requested additional information from the reporter label Sep 10, 2025
@bpg bpg marked this pull request as draft September 10, 2025 02:59
@bpg bpg removed the ⌛ pending author's response Requested additional information from the reporter label Sep 10, 2025
@Vaneixus Vaneixus force-pushed the Update_Disk_Via_Import branch from 4006809 to 43d1733 Compare September 22, 2025 00:46
@Vaneixus Vaneixus marked this pull request as ready for review September 22, 2025 00:47
@Vaneixus
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fix to allow updating a VM's boot disk by re-importing it, which correctly identifies that a VM shutdown is required. The changes are well-propagated from the disk update logic to the main VM update function, including logic to prevent redundant shutdowns. My review includes a suggestion to fix a logic issue in the VM start/stop handling and to add test coverage for the new disk update scenario.


// Call the Update function
_, err = Update(ctx, client, nodeName, vmID, resourceData, planDisks, currentDisks, updateBody)
_, _, err = Update(ctx, client, nodeName, vmID, resourceData, planDisks, currentDisks, updateBody)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Update function signature has changed, and this test was updated to compile. However, there is no test case that covers the new functionality of updating a disk with import_from. It would be valuable to add a new test to ensure that when import_from is changed on an existing disk, the shutdownBeforeUpdate flag is correctly returned as true from the Update function.

@Vaneixus
Copy link
Contributor Author

Vaneixus commented Sep 22, 2025

Hello BPG, I already ran a very basic update on an existing cluster, it seems to work according to PVE's logs. feel free to run a test and check it out. I haven't actually checked the content inside of the disks, but proxmox gave me a new import entry in the logs so it should have replaced it successfully. I will probably be testing other stuff such as no change. but the basic functionality seems to be working. I will also probably have an another change or two to be done, such as in case the VM is already shutdown since it seems I am not handling that as of yet.

@Vaneixus Vaneixus marked this pull request as draft September 22, 2025 01:07
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.

2 participants