Skip to content

Commit

Permalink
allocator: reduce cyclomatic complexity
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Apr 12, 2019
1 parent 48808e3 commit 7754e40
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions manager/allocator/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,24 +1055,22 @@ func (a *Allocator) allocateNode(ctx context.Context, node *api.Node, existingAd
if _, ok := nwIDs[na.Network.ID]; ok {
// attachment belongs to one of the networks, so keep it
attachments = append(attachments, na)
} else {
// free the attachment and remove it from the node's attachments by
// re-slicing
if err := a.netCtx.nwkAllocator.DeallocateAttachment(node, na); err != nil {
// if deallocation fails, there's nothing we can do besides log
// an error and keep going
log.G(ctx).WithError(err).Errorf(
"error deallocating attachment for network %v on node %v",
na.Network.ID, node.ID,
)
}
// strictly speaking, nothing was allocated, but something was
// deallocated and that counts.
allocated = true
// also, set the somethingWasDeallocated flag so the allocator
// knows that it can now try again.
a.netCtx.somethingWasDeallocated = true
continue
}

if err := a.netCtx.nwkAllocator.DeallocateAttachment(node, na); err != nil {
// failed to deallocate; there's nothing we can do besides log an error and keep going
log.G(ctx).WithError(err).Errorf(
"error deallocating attachment for network %v on node %v",
na.Network.ID, node.ID,
)
}
// strictly speaking, nothing was allocated, but something was
// deallocated and that counts.
allocated = true
// also, set the somethingWasDeallocated flag so the allocator
// knows that it can now try again.
a.netCtx.somethingWasDeallocated = true
}
node.Attachments = attachments

Expand Down

0 comments on commit 7754e40

Please sign in to comment.