Skip to content

Commit

Permalink
allocator: handle "restore" earlier
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Feb 12, 2019
1 parent 8867139 commit e3f7b31
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions manager/allocator/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,25 +1006,22 @@ func (a *Allocator) allocateNode(ctx context.Context, node *api.Node, existingAd
}
}

if lbAttachment != nil {
if nc.nwkAllocator.IsAttachmentAllocated(node, lbAttachment) {
continue
}
if existingAddressesOnly && (lbAttachment == nil || len(lbAttachment.Addresses) == 0) {
// we're restoring state, don't allocate new (or empty) attachments
continue
}

if nc.nwkAllocator.IsAttachmentAllocated(node, lbAttachment) {
// already allocated; we're done
continue
}

if lbAttachment == nil {
// if we're restoring state, we should not add an attachment here.
if existingAddressesOnly {
continue
}
// network was not yet allocated to the node, so create a new attachment
lbAttachment = &api.NetworkAttachment{}
node.Attachments = append(node.Attachments, lbAttachment)
}

if existingAddressesOnly && len(lbAttachment.Addresses) == 0 {
continue
}

lbAttachment.Network = network.Copy()
if err := a.netCtx.nwkAllocator.AllocateAttachment(node, lbAttachment); err != nil {
log.G(ctx).WithError(err).Errorf("Failed to allocate network resources for node %s", node.ID)
Expand Down

0 comments on commit e3f7b31

Please sign in to comment.