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): handle PVE node availability in VM datasource #1715

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

bpg
Copy link
Owner

@bpg bpg commented Jan 17, 2025

  • Added error handling for HTTP error code 595 in vmsRead, providing a warning if a node is not available, which may result in an incomplete VM list.

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

3 VMs provisioned in a test cluster of 3 nodes, one node with one VM is down.

Screenshot 2025-01-17 at 12 19 30 PM

This simple config

data "proxmox_virtual_environment_vms" "vms" {
}

output "vms" {
  value = data.proxmox_virtual_environment_vms.vms.vms
}

produced this output on apply:

❯ tofu apply -auto-approve
data.proxmox_virtual_environment_vms.vms: Reading...
data.proxmox_virtual_environment_vms.vms: Read complete after 0s [id=6595adac-e681-4906-bd76-e67e3262d862]

No changes. Your infrastructure matches the configuration.

OpenTofu has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
╷
│ Warning: node "pve-t2" is not available - VM list may be incomplete
│ 
│   with data.proxmox_virtual_environment_vms.vms,
│   on main.tf line 29, in data "proxmox_virtual_environment_vms" "vms":
│   29: data "proxmox_virtual_environment_vms" "vms" {
│ 
╵

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

vms = tolist([
  {
    "name" = "test1"
    "node_name" = "pve-t1"
    "status" = "stopped"
    "tags" = tolist([
      "tag1",
      "tag2",
    ])
    "template" = false
    "vm_id" = 100
  },
  {
    "name" = "test3"
    "node_name" = "pve-t3"
    "status" = "stopped"
    "tags" = tolist([
      "tag1",
      "tag3",
    ])
    "template" = false
    "vm_id" = 102
  },
])

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling when listing VMs from the Proxmox API
    • Enhanced robustness of VM data retrieval process
  • Documentation

    • Updated function comment to clarify VM reading behavior

- Added error handling for HTTP error code 595 in vmsRead, providing a warning if a node is not available, which may result in an incomplete VM list.

Signed-off-by: Pavel Boldyrev <[email protected]>
Copy link

coderabbitai bot commented Jan 17, 2025

Walkthrough

The changes modify the VM listing functionality in the Proxmox Terraform provider to handle scenarios where a node in a cluster is offline. Specifically, the code now captures a specific HTTP error code (595) during VM listing operations, allowing the function to continue processing and append a warning diagnostic instead of completely failing. This enhances the provider's resilience when working with multi-node Proxmox clusters where some nodes might be temporarily unavailable.

Changes

File Change Summary
proxmoxtf/datasource/vms.go - Added imports for errors and proxmoxapi packages
- Updated function comment for vmRead
- Implemented error handling for HTTP 595 error code

Assessment against linked issues

Objective Addressed Explanation
Handle VM listing when node is offline [#692]
List VMs without failing on offline nodes

Possibly related PRs

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
proxmoxtf/datasource/vms.go (2)

91-91: Enhance function documentation.

While the updated comment is more accurate, it could be more descriptive about the function's behavior, especially regarding node availability handling.

-// vmRead reads the VMs.
+// vmRead reads VMs from available Proxmox nodes. If a node is unavailable (HTTP 595),
+// it will be skipped with a warning, and the function will continue with other nodes.

126-134: Enhance error handling and user feedback.

The error handling implementation is good, but could be improved with more detailed feedback and logging.

 var httpError *proxmoxapi.HTTPError
 if errors.As(e, &httpError) && httpError.Code == 595 {
+    // Log the original error for debugging
+    config.Logger.Debug("failed to list VMs", "node", nodeName, "error", e)
+
     diags = append(diags, diag.Diagnostic{
         Severity: diag.Warning,
-        Summary:  fmt.Sprintf("node %q is not available - VM list may be incomplete", nodeName),
+        Summary:  fmt.Sprintf("node %q is not available (HTTP 595) - VM list may be incomplete", nodeName),
+        Detail:   "Please check the node's status in the Proxmox web interface and ensure it's running and accessible.",
     })

     continue
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eccd55f and 69db795.

📒 Files selected for processing (1)
  • proxmoxtf/datasource/vms.go (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: qodana
🔇 Additional comments (2)
proxmoxtf/datasource/vms.go (2)

11-11: LGTM! Import changes are appropriate.

The added imports for errors and proxmoxapi packages are necessary for the new error handling logic.

Also applies to: 24-24


Line range hint 91-135: Overall implementation looks great! 👍

The changes successfully implement graceful handling of node unavailability in the VM datasource. The code:

  • Properly handles HTTP 595 errors
  • Provides clear user feedback
  • Continues processing available nodes
  • Uses correct error handling patterns

This enhancement will improve the user experience when working with partially available Proxmox clusters.

@bpg bpg merged commit 3ecd044 into main Jan 17, 2025
8 checks passed
@bpg bpg deleted the fix-list-vms-node-down branch January 17, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VM listing operations fail when node is offline
1 participant