Skip to content

Commit

Permalink
Merge pull request #7 from Nordix/bugfix-mael
Browse files Browse the repository at this point in the history
🐛 Trim trailing - in IPAddress object names
  • Loading branch information
metal3-io-bot authored Jun 12, 2020
2 parents 2da124b + fc469ef commit b9f902b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions ipam/ippool_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,8 @@ func (m *IPPoolManager) createAddress(ctx context.Context,
}

if allocatedAddress, ok := m.IPPool.Status.Allocations[addressClaim.Name]; ok {
formatedAddress := strings.Replace(
strings.Replace(string(allocatedAddress), ":", "-", -1), ".", "-", -1,
)
addressClaim.Status.Address = &corev1.ObjectReference{
Name: m.IPPool.Spec.NamePrefix + "-" + formatedAddress,
Name: m.formatAddressName(allocatedAddress),
Namespace: m.IPPool.Namespace,
}
return addresses, nil
Expand All @@ -295,12 +292,9 @@ func (m *IPPoolManager) createAddress(ctx context.Context,
if err != nil {
return addresses, err
}
formatedAddress := strings.Replace(
strings.Replace(string(allocatedAddress), ":", "-", -1), ".", "-", -1,
)

// Set the index and IPAddress names
addressName := m.IPPool.Spec.NamePrefix + "-" + formatedAddress
addressName := m.formatAddressName(allocatedAddress)

m.Log.Info("Address allocated", "Claim", addressClaim.Name, "address", allocatedAddress)

Expand Down Expand Up @@ -380,11 +374,8 @@ func (m *IPPoolManager) deleteAddress(ctx context.Context,
if ok {
// Try to get the IPAddress. if it succeeds, delete it
tmpM3Data := &ipamv1.IPAddress{}
formatedAddress := strings.Replace(
strings.Replace(string(allocatedAddress), ":", "-", -1), ".", "-", -1,
)
key := client.ObjectKey{
Name: m.IPPool.Spec.NamePrefix + "-" + formatedAddress,
Name: m.formatAddressName(allocatedAddress),
Namespace: m.IPPool.Namespace,
}
err := m.client.Get(ctx, key, tmpM3Data)
Expand Down Expand Up @@ -518,3 +509,10 @@ func addOffsetToIP(ip, endIP net.IP, offset int) (net.IP, error) {
copy(ip[16-IPBytesLen:], IPBytes)
return ip, nil
}

// formatAddressName renders the name of the IPAddress objects
func (m *IPPoolManager) formatAddressName(address ipamv1.IPAddressStr) string {
return strings.TrimRight(m.IPPool.Spec.NamePrefix+"-"+strings.Replace(
strings.Replace(string(address), ":", "-", -1), ".", "-", -1,
), "-")
}

0 comments on commit b9f902b

Please sign in to comment.