Skip to content

Ensure controlapi Server always has an up to date allocator#2231

Closed
ijc wants to merge 1 commit intomoby:masterfrom
ijc:controlapi-network-allocator
Closed

Ensure controlapi Server always has an up to date allocator#2231
ijc wants to merge 1 commit intomoby:masterfrom
ijc:controlapi-network-allocator

Conversation

@ijc
Copy link
Copy Markdown
Contributor

@ijc ijc commented Jun 9, 2017

Currently the allocator is only created when a node becomes the leader, which
is (almost always) after the controlapi.NewServer call. Hence the server is
always being passed a m.allocator which is nil.

In addition the server wasn't actually remembering the allocator it was passed.

Add a second layer of indirection to the allocator stashed by the controlapi
Server, so it will always see the latest version of m.allocator.

This stops #2230 from happening, but is really only a stopgap until a more
satisfactory solution can be found.

This regression was made by me in fb74191 ("Convert NetworkAllocator to an
interface"). Add a call to CreateNetwork to TestManager intended to exercise
the code path through validateNetwork to allocator.IsBuiltinNetworkDriver.

Signed-off-by: Ian Campbell ian.campbell@docker.com

Currently the allocator is only created when a node becomes the leader, which
is (almost always) after the controlapi.NewServer call. Hence the server is
always being passed a m.allocator which is nil.

In addition the server wasn't actually remembering the allocator it was passed.

Add a second layer of indirection to the allocator stashed by the controlapi
Server, so it will always see the latest version of m.allocator.

This stops moby#2230 from happening, but is really only a stopgap until a more
satisfactory solution can be found.

This regression was made by me in fb74191 ("Convert NetworkAllocator to an
interface"). Add a call to CreateNetwork to TestManager intended to exercise
the code path through validateNetwork to allocator.IsBuiltinNetworkDriver.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
@ijc
Copy link
Copy Markdown
Contributor Author

ijc commented Jun 9, 2017

Not very happy with this long term, but will discuss potential proper solutions over on #2230.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 9, 2017

Codecov Report

Merging #2231 into master will decrease coverage by 0.06%.
The diff coverage is 75%.

@@            Coverage Diff             @@
##           master    #2231      +/-   ##
==========================================
- Coverage   60.16%   60.09%   -0.07%     
==========================================
  Files         124      124              
  Lines       20156    20157       +1     
==========================================
- Hits        12126    12114      -12     
- Misses       6669     6674       +5     
- Partials     1361     1369       +8

// - Returns an error if the creation fails.
func (s *Server) CreateNetwork(ctx context.Context, request *api.CreateNetworkRequest) (*api.CreateNetworkResponse, error) {
if err := validateNetworkSpec(request.Spec, s.a, s.pg); err != nil {
if err := validateNetworkSpec(request.Spec, *(s.a), s.pg); err != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*s.a

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moot given the subsequent discussion, but I could have sworn that didn't compile. I just tried again and it is fine, no idea what I had done differently on my first try.

@aaronlehmann
Copy link
Copy Markdown
Collaborator

I'm not enthusiastic about this solution. It's not obvious to me that the pointer read can't race with becomeLeader (and it's probably even less obvious to the race detector). I also don't see any guarantee that a.netCtx is initialized by this point - it looks like this happens in another goroutine from creation of the allocator.

I think we should move IsBuiltInDriver out of the allocator interface. The NetworkModel interface you suggested sounds good, as long as we are able to create the object backing this interface before the actual allocator is created.

Perhaps a simple temporary solution would be to define an interface specifically for checking whether a driver is built-in, initializing that before everything else, and passing it into controlapi instead of an allocator?

@ijc
Copy link
Copy Markdown
Contributor Author

ijc commented Jun 12, 2017

Short term I'll switch IsBuiltInDriver to be similar to PredefinedNetworks i.e. just wrap cnmallocator internally for the time being since CNM is currently the only option.

I'll then incorporate the NetworkModel interface idea into a future PR when I add the CNI support. Based on my POC I think the object can be created well in advance of even creating the manager object.

@ijc
Copy link
Copy Markdown
Contributor Author

ijc commented Jun 12, 2017

Replacing with #2240

@ijc ijc closed this Jun 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants