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

Improve AssignmentError message #366

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkg/allocate/allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (

// AssignmentError defines an IP assignment error.
type AssignmentError struct {
firstIP net.IP
lastIP net.IP
ipnet net.IPNet
firstIP net.IP
lastIP net.IP
ipnet net.IPNet
excludeRanges []string
}

func (a AssignmentError) Error() string {
return fmt.Sprintf("Could not allocate IP in range: ip: %v / - %v / range: %#v", a.firstIP, a.lastIP, a.ipnet)
return fmt.Sprintf("Could not allocate IP in range: ip: %v / - %v / range: %s / excludeRanges: %v",
a.firstIP, a.lastIP, a.ipnet.String(), a.excludeRanges)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I must do a.ipnet.String() because otherwise it looks like this:

range: {2000:: ffffffffffffffff0000000000000000} 

And with it it looks like this:

range: 2000::/64

Copy link
Member

Choose a reason for hiding this comment

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

💯

}

// AssignIP assigns an IP using a range and a reserve list.
Expand Down Expand Up @@ -129,7 +131,7 @@ func IterateForAssignment(ipnet net.IPNet, rangeStart net.IP, rangeEnd net.IP, r
}

// No IP address for assignment found, return an error.
return net.IP{}, reserveList, AssignmentError{firstIP, lastIP, ipnet}
return net.IP{}, reserveList, AssignmentError{firstIP, lastIP, ipnet, excludeRanges}
}

// skipExcludedSubnets iterates through all subnets and checks if ip is part of them. If i is part of one of the subnets,
Expand Down
Loading