@@ -278,11 +278,8 @@ func (m *IPPoolManager) createAddress(ctx context.Context,
278278 }
279279
280280 if allocatedAddress , ok := m .IPPool .Status .Allocations [addressClaim .Name ]; ok {
281- formatedAddress := strings .Replace (
282- strings .Replace (string (allocatedAddress ), ":" , "-" , - 1 ), "." , "-" , - 1 ,
283- )
284281 addressClaim .Status .Address = & corev1.ObjectReference {
285- Name : m .IPPool . Spec . NamePrefix + "-" + formatedAddress ,
282+ Name : m .formatAddressName ( allocatedAddress ) ,
286283 Namespace : m .IPPool .Namespace ,
287284 }
288285 return addresses , nil
@@ -295,12 +292,9 @@ func (m *IPPoolManager) createAddress(ctx context.Context,
295292 if err != nil {
296293 return addresses , err
297294 }
298- formatedAddress := strings .Replace (
299- strings .Replace (string (allocatedAddress ), ":" , "-" , - 1 ), "." , "-" , - 1 ,
300- )
301295
302296 // Set the index and IPAddress names
303- addressName := m .IPPool . Spec . NamePrefix + "-" + formatedAddress
297+ addressName := m .formatAddressName ( allocatedAddress )
304298
305299 m .Log .Info ("Address allocated" , "Claim" , addressClaim .Name , "address" , allocatedAddress )
306300
@@ -380,11 +374,8 @@ func (m *IPPoolManager) deleteAddress(ctx context.Context,
380374 if ok {
381375 // Try to get the IPAddress. if it succeeds, delete it
382376 tmpM3Data := & ipamv1.IPAddress {}
383- formatedAddress := strings .Replace (
384- strings .Replace (string (allocatedAddress ), ":" , "-" , - 1 ), "." , "-" , - 1 ,
385- )
386377 key := client.ObjectKey {
387- Name : m .IPPool . Spec . NamePrefix + "-" + formatedAddress ,
378+ Name : m .formatAddressName ( allocatedAddress ) ,
388379 Namespace : m .IPPool .Namespace ,
389380 }
390381 err := m .client .Get (ctx , key , tmpM3Data )
@@ -518,3 +509,10 @@ func addOffsetToIP(ip, endIP net.IP, offset int) (net.IP, error) {
518509 copy (ip [16 - IPBytesLen :], IPBytes )
519510 return ip , nil
520511}
512+
513+ // formatAddressName renders the name of the IPAddress objects
514+ func (m * IPPoolManager ) formatAddressName (address ipamv1.IPAddressStr ) string {
515+ return strings .TrimRight (m .IPPool .Spec .NamePrefix + "-" + strings .Replace (
516+ strings .Replace (string (address ), ":" , "-" , - 1 ), "." , "-" , - 1 ,
517+ ), "-" )
518+ }
0 commit comments