Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor allocator to attempt to reduce complexity #2823

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allocator: reduce cyclomatic complexity
Signed-off-by: Sebastiaan van Stijn <[email protected]>
thaJeztah committed Jul 29, 2023
commit a1abcca4862ed6b66ace45ccd0b92dc1ff829df5
32 changes: 15 additions & 17 deletions manager/allocator/network.go
Original file line number Diff line number Diff line change
@@ -1057,24 +1057,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