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

Added trailing 0 to ipv6 ranges that end in ":" #297

Merged
merged 6 commits into from
Feb 8, 2023
Merged
Changes from 1 commit
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
18 changes: 16 additions & 2 deletions pkg/storage/kubernetes/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ func (i *KubernetesIPAM) GetIPPool(ctx context.Context, ipRange string) (storage

func NormalizeRange(ipRange string) string {
// v6 filter
if ipRange[len(ipRange)-1] == ':' {
ipRange = ipRange + "0"
}
normalized := strings.ReplaceAll(ipRange, ":", "-")

// replace subnet cidr slash
normalized = strings.ReplaceAll(normalized, "/", "-")
return normalized
Expand Down Expand Up @@ -178,7 +182,12 @@ func (i *KubernetesIPAM) GetOverlappingRangeStore() (storage.OverlappingRangeSto
func (c *KubernetesOverlappingRangeStore) IsAllocatedInOverlappingRange(ctx context.Context, ip net.IP) (bool, error) {

// IPv6 doesn't make for valid CR names, so normalize it.
normalizedip := strings.ReplaceAll(fmt.Sprint(ip), ":", "-")
ipStr := fmt.Sprint(ip)
if ipStr[len(ipStr)-1] == ':' {
ipStr += "0"
logging.Debugf("modified: %s", ipStr)
}
normalizedip := strings.ReplaceAll(ipStr, ":", "-")

logging.Debugf("OverlappingRangewide allocation check for IP: %v", normalizedip)

Expand All @@ -199,7 +208,12 @@ func (c *KubernetesOverlappingRangeStore) IsAllocatedInOverlappingRange(ctx cont
// UpdateOverlappingRangeAllocation updates clusterwide allocation for overlapping ranges.
func (c *KubernetesOverlappingRangeStore) UpdateOverlappingRangeAllocation(ctx context.Context, mode int, ip net.IP, containerID string, podRef string) error {
// Normalize the IP
normalizedip := strings.ReplaceAll(fmt.Sprint(ip), ":", "-")
ipStr := fmt.Sprint(ip)
if ipStr[len(ipStr)-1] == ':' {
ipStr += "0"
logging.Debugf("modified: %s", ipStr)
}
normalizedip := strings.ReplaceAll(ipStr, ":", "-")

clusteripres := &whereaboutsv1alpha1.OverlappingRangeIPReservation{
ObjectMeta: metav1.ObjectMeta{Name: normalizedip, Namespace: c.namespace},
Expand Down