-
Notifications
You must be signed in to change notification settings - Fork 265
Feat: HA rules #463
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: HA rules #463
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for HA (High Availability) rules introduced in Proxmox VE 9.0, including comprehensive test coverage for all pure functions. The implementation provides full CRUD operations for both node affinity and resource affinity rules with proper validation and API integration.
Key changes:
- Complete HA rules implementation with version checking for PVE 9.0+
- Comprehensive test suite covering all scenarios and edge cases
- New test data utilities for HA rule ID validation
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| proxmox/config__ha__rules.go | Core HA rules implementation with types, validation, and API methods |
| proxmox/config__ha__rules_test.go | Comprehensive test suite covering all HA rule functionality |
| test/data/test_data_ha/type_HaRuleID.go | Test data utilities for HA rule ID validation scenarios |
| proxmox/client__new.go | Extended client interface with HA rule methods |
| proxmox/client__api.go | API client implementation for HA rule endpoints |
| proxmox/client.go | Added version constant for PVE 9.0 |
| internal/array/array.go | New utility package for array operations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if err := haVersionCheck(ctx, c); err != nil { | ||
| return err | ||
| } | ||
| if err := ha.validateUpdate(); err != nil { |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return statement after error check. The error should be returned if validation fails.
| if err := ha.validateUpdate(); err != nil { | |
| if err := ha.validateUpdate(); err != nil { | |
| return err |
proxmox/config__ha__rules.go
Outdated
| HaNodeAffinityRule_Error_GuestsEmpty = "guests must not be empty" | ||
| HaNodeAffinityRule_Error_GuestsRequired = "guests must be specified during creation" | ||
| HaNodeAffinityRule_Error_Kind = "rule is not a node affinity rule" | ||
| HaNodeAffinityRule_Error_NodesEmpty = "modes must not be empty" |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in error message: 'modes' should be 'nodes'.
| HaNodeAffinityRule_Error_NodesEmpty = "modes must not be empty" | |
| HaNodeAffinityRule_Error_NodesEmpty = "nodes must not be empty" |
proxmox/config__ha__rules.go
Outdated
| resoures := make([]string, len(guests)) | ||
| for i := range guests { | ||
| switch (guests)[i].vmType { | ||
| case GuestQemu: | ||
| resoures[i] = haGuestPrefixVm + (guests)[i].vmId.String() | ||
| case GuestLxc: | ||
| resoures[i] = haGuestPrefixCt + (guests)[i].vmId.String() | ||
| } | ||
| } | ||
| params[haRuleApiKeyResources] = resoures |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable name 'resoures' should be 'resources'.
| resoures := make([]string, len(guests)) | |
| for i := range guests { | |
| switch (guests)[i].vmType { | |
| case GuestQemu: | |
| resoures[i] = haGuestPrefixVm + (guests)[i].vmId.String() | |
| case GuestLxc: | |
| resoures[i] = haGuestPrefixCt + (guests)[i].vmId.String() | |
| } | |
| } | |
| params[haRuleApiKeyResources] = resoures | |
| resources := make([]string, len(guests)) | |
| for i := range guests { | |
| switch (guests)[i].vmType { | |
| case GuestQemu: | |
| resources[i] = haGuestPrefixVm + (guests)[i].vmId.String() | |
| case GuestLxc: | |
| resources[i] = haGuestPrefixCt + (guests)[i].vmId.String() | |
| } | |
| } | |
| params[haRuleApiKeyResources] = resources |
proxmox/config__ha__rules.go
Outdated
| var haRuleIdRegex = regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`) | ||
|
|
||
| const ( | ||
| HaRuleID_Error_MinLength = `ha rule ID must atleast be 2 characters` |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: 'atleast' should be 'at least'.
| HaRuleID_Error_MinLength = `ha rule ID must atleast be 2 characters` | |
| HaRuleID_Error_MinLength = `ha rule ID must at least be 2 characters` |
proxmox/config__ha__rules.go
Outdated
| HaRuleID_Error_MinLength = `ha rule ID must atleast be 2 characters` | ||
| HaRuleID_Error_MaxLength = `ha rule ID has a maximum of 128 characters` | ||
| HaRuleID_Error_Invalid = `ha rule ID did not match the following regex '^[a-zA-Z][a-zA-Z0-9\-_]{2,127}$'` | ||
| HaRuleID_Error_Start = `ha rule ID can only with a lower or upper case letter` |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar error in message: should be 'ha rule ID can only start with a lower or upper case letter'.
| HaRuleID_Error_Start = `ha rule ID can only with a lower or upper case letter` | |
| HaRuleID_Error_Start = `ha rule ID can only start with a lower or upper case letter` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
proxmox/config__ha__rules.go
Outdated
| return nil | ||
| } | ||
|
|
||
| // HaRuleID has a minimim of 2 characters and max of 128 characters. |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the comment: 'minimim' should be 'minimum'
| // HaRuleID has a minimim of 2 characters and max of 128 characters. | |
| // HaRuleID has a minimum of 2 characters and max of 128 characters. |
| const ( | ||
| HaRuleID_Error_MinLength = `ha rule ID must at least be 2 characters` | ||
| HaRuleID_Error_MaxLength = `ha rule ID has a maximum of 128 characters` | ||
| HaRuleID_Error_Invalid = `ha rule ID did not match the following regex '^[a-zA-Z][a-zA-Z0-9\-_]{2,127}$'` |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message references a regex pattern that doesn't match the actual regex used in the code. The actual regex is ^[a-zA-Z0-9\-_]+$ but the error message shows ^[a-zA-Z][a-zA-Z0-9\-_]{2,127}$
| HaRuleID_Error_Invalid = `ha rule ID did not match the following regex '^[a-zA-Z][a-zA-Z0-9\-_]{2,127}$'` | |
| HaRuleID_Error_Invalid = `ha rule ID did not match the following regex '^[a-zA-Z0-9\-_]+$'` |
proxmox/config__ha__rules.go
Outdated
| builder.WriteString(string(nodes[i].Node.String())) | ||
| } else { | ||
| builder.WriteString(string(nodes[i].Node.String())) |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant string conversion. nodes[i].Node.String() already returns a string, so the outer string() conversion is unnecessary and should be removed.
| builder.WriteString(string(nodes[i].Node.String())) | |
| } else { | |
| builder.WriteString(string(nodes[i].Node.String())) | |
| builder.WriteString(nodes[i].Node.String()) | |
| } else { | |
| builder.WriteString(nodes[i].Node.String()) |
proxmox/config__ha__rules.go
Outdated
| builder.WriteString(string(nodes[i].Node.String())) | ||
| } else { | ||
| builder.WriteString(string(nodes[i].Node.String())) |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant string conversion. nodes[i].Node.String() already returns a string, so the outer string() conversion is unnecessary and should be removed.
| builder.WriteString(string(nodes[i].Node.String())) | |
| } else { | |
| builder.WriteString(string(nodes[i].Node.String())) | |
| builder.WriteString(nodes[i].Node.String()) | |
| } else { | |
| builder.WriteString(nodes[i].Node.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // HaRuleID has a minimum of 2 characters and max of 128 characters. | ||
| type HaRuleID string | ||
|
|
||
| var haRuleIdRegex = regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`) |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern allows underscores but the error message on line 834 suggests underscores are not allowed. The error message should be updated to match the actual regex pattern or the regex should be corrected to exclude underscores if they're not intended to be valid.
| var haRuleIdRegex = regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`) | |
| var haRuleIdRegex = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\-_]{1,127}$`) |
Add support for the new HA rules introduced in PVE 9.0
Add tests for all pure functions.