Skip to content

Conversation

@Tinyblargon
Copy link
Collaborator

@Tinyblargon Tinyblargon commented Sep 27, 2025

Adds functionality to delete a HA Resource.

Removes unused rawDigest from the HA rules.

Related to Telmate/terraform-provider-proxmox#1394

@Tinyblargon Tinyblargon requested a review from Copilot September 27, 2025 19:48
@Tinyblargon Tinyblargon self-assigned this Sep 27, 2025
@Tinyblargon Tinyblargon added type/refactoring Existing code has been cleaned up. There should be no new functionality type/feature Completely new functionality. modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files test/done This PR has been tested and the result was succesfull labels Sep 27, 2025
Copy link
Contributor

Copilot AI left a 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 functionality to delete High Availability (HA) resources and removes unused rawDigest fields from HA rule structures. The implementation includes proper error handling for cases where the HA resource doesn't exist.

  • Adds DeleteHaResource method for GuestID with comprehensive error handling
  • Removes unused rawDigest field from HaNodeAffinityRule and HaResourceAffinityRule structs
  • Updates corresponding test cases to reflect the removal of rawDigest

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
proxmox/error.go Adds new error types for HA resource deletion scenarios
proxmox/config__guest.go Implements the main HA resource deletion functionality
proxmox/client__new.go Adds interface method for HA resource deletion
proxmox/client__new__mock.go Implements mock for HA resource deletion
proxmox/client__api.go Adds low-level API interface and implementation
proxmox/client__api__mock.go Adds mock implementation for API interface
proxmox/config__ha__rules.go Removes unused rawDigest fields from HA rule structs
proxmox/config__ha__rules_test.go Updates tests to remove rawDigest references

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

func (id GuestID) deleteHaResource(ctx context.Context, c clientApiInterface) error {
err := c.deleteHaResource(ctx, id)
if err != nil {
if strings.HasPrefix(err.Error(), "500 cannot delete service") {
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

Using string prefix matching on error messages is fragile and could break if the API error format changes. Consider checking for specific HTTP status codes or using structured error types instead.

Suggested change
if strings.HasPrefix(err.Error(), "500 cannot delete service") {
// Try to check for HTTP status code 500 and error message "cannot delete service"
type httpError interface {
StatusCode() int
Error() string
}
if herr, ok := err.(httpError); ok {
if herr.StatusCode() == 500 && strings.Contains(herr.Error(), "cannot delete service") {
return Error.haResourceDoesNotExist(id)
}
} else if strings.HasPrefix(err.Error(), "500 cannot delete service") {
// Fallback to string matching if error type does not expose status code

Copilot uses AI. Check for mistakes.
@Tinyblargon Tinyblargon merged commit b7a8fcf into Telmate:master Sep 27, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files test/done This PR has been tested and the result was succesfull type/feature Completely new functionality. type/refactoring Existing code has been cleaned up. There should be no new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant