-
Notifications
You must be signed in to change notification settings - Fork 616
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
Fix IP overlap with empty EndpointSpec #2505
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,7 +244,7 @@ func (a *Allocator) doNetworkAlloc(ctx context.Context, ev events.Event) { | |
break | ||
} | ||
|
||
if err := a.allocateService(ctx, s); err != nil { | ||
if err := a.allocateService(ctx, s, false); err != nil { | ||
log.G(ctx).WithError(err).Errorf("Failed allocation for service %s", s.ID) | ||
break | ||
} | ||
|
@@ -274,7 +274,7 @@ func (a *Allocator) doNetworkAlloc(ctx context.Context, ev events.Event) { | |
} | ||
updatePortsInHostPublishMode(s) | ||
} else { | ||
if err := a.allocateService(ctx, s); err != nil { | ||
if err := a.allocateService(ctx, s, false); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a comment on why restart flag is false here. |
||
log.G(ctx).WithError(err).Errorf("Failed allocation during update of service %s", s.ID) | ||
break | ||
} | ||
|
@@ -587,8 +587,8 @@ func (a *Allocator) allocateServices(ctx context.Context, existingAddressesOnly | |
continue | ||
} | ||
|
||
if err := a.allocateService(ctx, s); err != nil { | ||
log.G(ctx).WithError(err).Errorf("failed allocating service %s during init", s.ID) | ||
if err := a.allocateService(ctx, s, existingAddressesOnly); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Please add a comment on how existingAddressesOnly relates to the restart flag which is an arg for allocateService() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change the name of the variable to match to show that the relation is that they are the same thing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean to make this change ? I don't see it in the patch @fcrisciani There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the name of the variable is changed inside the allocateService not here, I kept the original name |
||
log.G(ctx).WithField("existingAddressesOnly", existingAddressesOnly).WithError(err).Errorf("failed allocating service %s during init", s.ID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can this comment be made more clear? Should be it something like "failed to allocate network..." or something of that nature, perhaps with more info? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error field will give that information. |
||
continue | ||
} | ||
allocatedServices = append(allocatedServices, s) | ||
|
@@ -940,7 +940,10 @@ func updatePortsInHostPublishMode(s *api.Service) { | |
s.Endpoint.Spec = s.Spec.Endpoint.Copy() | ||
} | ||
|
||
func (a *Allocator) allocateService(ctx context.Context, s *api.Service) error { | ||
// allocateService takes care to align the desired state with the spec passed | ||
// the last parameter is true only during restart when the data is read from raft | ||
// and used to build internal state | ||
func (a *Allocator) allocateService(ctx context.Context, s *api.Service, existingAddressesOnly bool) error { | ||
nc := a.netCtx | ||
|
||
if s.Spec.Endpoint != nil { | ||
|
@@ -972,7 +975,9 @@ func (a *Allocator) allocateService(ctx context.Context, s *api.Service) error { | |
&api.Endpoint_VirtualIP{NetworkID: nc.ingressNetwork.ID}) | ||
} | ||
} | ||
} else if s.Endpoint != nil { | ||
} else if s.Endpoint != nil && !existingAddressesOnly { | ||
// if we are in the restart phase there is no reason to try to deallocate anything because the state | ||
// is not there | ||
// service has no user-defined endpoints while has already allocated network resources, | ||
// need deallocated. | ||
if err := nc.nwkAllocator.DeallocateService(s); err != nil { | ||
|
@@ -1188,7 +1193,7 @@ func (a *Allocator) procUnallocatedServices(ctx context.Context) { | |
var allocatedServices []*api.Service | ||
for _, s := range nc.unallocatedServices { | ||
if !nc.nwkAllocator.IsServiceAllocated(s) { | ||
if err := a.allocateService(ctx, s); err != nil { | ||
if err := a.allocateService(ctx, s, false); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a comment on why restart flag is false here. |
||
log.G(ctx).WithError(err).Debugf("Failed allocation of unallocated service %s", s.ID) | ||
continue | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add a comment on why restart flag is false here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put a comment on the allocateService itself, instead to spread a one line everywhere saying that is not a restart case