@@ -294,10 +294,10 @@ func (i *ipamer) ReleaseChildPrefix(ctx context.Context, child *Prefix) error {
294
294
func (i * ipamer ) releaseChildPrefixInternal (ctx context.Context , namespace string , child * Prefix ) error {
295
295
parent , err := i .PrefixFrom (ctx , child .ParentCidr )
296
296
if err != nil {
297
- return fmt .Errorf ("%w: unable to find prefix for cidr:%s error:%s" , ErrNotFound , child .ParentCidr , err .Error ())
297
+ return fmt .Errorf ("%w: unable to find prefix for cidr:%q error:%s" , ErrNotFound , child .ParentCidr , err .Error ())
298
298
}
299
- if parent == nil {
300
- return fmt .Errorf ("prefix %s is no child prefix" , child .Cidr )
299
+ if parent == nil || ! parent . isParent {
300
+ return fmt .Errorf ("prefix:%q is no child prefix" , child .Cidr )
301
301
}
302
302
if len (child .ips ) > 2 {
303
303
return fmt .Errorf ("prefix %s has ips, deletion not possible" , child .Cidr )
@@ -306,12 +306,12 @@ func (i *ipamer) releaseChildPrefixInternal(ctx context.Context, namespace strin
306
306
parent .availableChildPrefixes [child .Cidr ] = true
307
307
_ , err = i .storage .UpdatePrefix (ctx , * parent , namespace )
308
308
if err != nil {
309
- return fmt .Errorf ("unable to release prefix %v :%w" , child , err )
309
+ return fmt .Errorf ("unable to update parent:%q to release child prefix:%q :%w" , child . ParentCidr , child . Cidr , err )
310
310
}
311
311
312
312
_ , err = i .DeletePrefix (ctx , child .Cidr )
313
313
if err != nil {
314
- return fmt .Errorf ("unable to release prefix %v :%w" , child , err )
314
+ return fmt .Errorf ("unable to delete child prefix:%q :%w" , child . Cidr , err )
315
315
}
316
316
317
317
return nil
0 commit comments