Skip to content

Commit

Permalink
Better error messages for release child prefix (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Jul 15, 2024
1 parent 1503103 commit 79a7226
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ func (i *ipamer) ReleaseChildPrefix(ctx context.Context, child *Prefix) error {
func (i *ipamer) releaseChildPrefixInternal(ctx context.Context, namespace string, child *Prefix) error {
parent, err := i.PrefixFrom(ctx, child.ParentCidr)
if err != nil {
return fmt.Errorf("%w: unable to find prefix for cidr:%s error:%s", ErrNotFound, child.ParentCidr, err.Error())
return fmt.Errorf("%w: unable to find prefix for cidr:%q error:%s", ErrNotFound, child.ParentCidr, err.Error())
}
if parent == nil {
return fmt.Errorf("prefix %s is no child prefix", child.Cidr)
if parent == nil || !parent.isParent {
return fmt.Errorf("prefix:%q is no child prefix", child.Cidr)
}
if len(child.ips) > 2 {
return fmt.Errorf("prefix %s has ips, deletion not possible", child.Cidr)
Expand All @@ -306,12 +306,12 @@ func (i *ipamer) releaseChildPrefixInternal(ctx context.Context, namespace strin
parent.availableChildPrefixes[child.Cidr] = true
_, err = i.storage.UpdatePrefix(ctx, *parent, namespace)
if err != nil {
return fmt.Errorf("unable to release prefix %v:%w", child, err)
return fmt.Errorf("unable to update parent:%q to release child prefix:%q :%w", child.ParentCidr, child.Cidr, err)
}

_, err = i.DeletePrefix(ctx, child.Cidr)
if err != nil {
return fmt.Errorf("unable to release prefix %v:%w", child, err)
return fmt.Errorf("unable to delete child prefix:%q :%w", child.Cidr, err)
}

return nil
Expand Down

0 comments on commit 79a7226

Please sign in to comment.