-
Notifications
You must be signed in to change notification settings - Fork 604
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
Add template support for network aliases #2250
base: master
Are you sure you want to change the base?
Conversation
These need to parameterize the user input, which is on https://github.com/docker/swarmkit/blob/master/api/types.proto#L503. However, to have an effect cluster-wide, so that it works on aliases, for instance, the template expansion needs to happen in the orchestrator. I haven't looked at this in awhile, so perhaps, @aaronlehmann can point you in the right direction. |
@stevvooe: Not too familiar with how aliases work; can you explain why they need to be expanded on the manager side? With a quick grep I don't see anywhere that the value is interpreted on the manager.
|
Probably not. Aliases are network-level aliases for the task, so I assume they need to be made available across the network, unless they are announced here? |
Do you mean service discovery? The managers are currently not involved in service discovery. |
template/expand.go
Outdated
if err != nil { | ||
return networks, errors.Wrap(err, "expanding alias failed") | ||
} | ||
aliases[indexAliases] = alias |
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.
This appears to be overwriting the Aliasses
entry in t.Networks
, not in the copy that was made above.
template/expand.go
Outdated
networks := make([]*api.NetworkAttachment, len(t.Networks)) | ||
|
||
ctx := NewContextFromTask(t) | ||
var err error |
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.
It's not necessary to predeclare this variable.
Perhaps the expansion needs to happen here then? https://github.com/docker/swarmkit/blob/master/manager/allocator/network.go#L641 |
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 think doing the template substitution in the executor, as this PR does, is the right approach. I don't see anywhere that network aliases are being used in manager code. That said, it would be great if others could confirm this is the case and that it won't change in the future if we add alternatives to gossip (cc @fcrisciani @abhinandanpb @sanimej @diogomonica @aluzzardi).
Note that for this to work in the context of docker, a similar change would be needed in the executor implemented in the moby/moby
repo.
@benturner Typically, we leave the spec untouched (I was really wrong above, please accept my apology). We need to figure the right place such that the aliases are run through templating, but then can propagate to the network correctly. @aaronlehmann has included some individuals who can help here. |
I'm worried that the executor is the wrong spot though... I followed the example of @stevvooe 's |
@benturner You're spot on, but I am not sure that it is in the manager. It is in some part of the executor, perhaps in the moby/moby version. |
Yes, nodes gossip amongst themselves to discover the tasks on each network. So far, the manager isn't involved in this process. |
Ah, I see. Sneaky... |
It should probably expand |
88e0443
to
910cbb5
Compare
Codecov Report
@@ Coverage Diff @@
## master #2250 +/- ##
==========================================
+ Coverage 60.34% 60.42% +0.08%
==========================================
Files 125 124 -1
Lines 20391 20288 -103
==========================================
- Hits 12305 12260 -45
+ Misses 6692 6653 -39
+ Partials 1394 1375 -19 |
910cbb5
to
07a90e1
Compare
@aaronlehmann I have updated the PR with your suggested changes and test coverage, please take another look? Thanks. |
LGTM It would be amazing if you have time to make the corresponding changes to https://github.com/moby/moby/tree/master/daemon/cluster/executor/container and test it in a real Docker setup, for example to confirm that the expanded aliases are propagated through the cluster. |
Hrm, I was sort of assuming that after this landed docker would just do a re-vendoring (isn't that what it's called?) of swarmkit and it would magically work... Is the code over there not related to this code? |
There are multiple executor implementations. The one you're editing here uses the docker remote API to control containers. It's only used for testing purposes, since when swarmkit is used as part of docker, it's not a separate daemon communicating with docker through its HTTP API. The code I linked to is the executor actually used inside of docker. It would need a similar change after vendoring swarmkit for this to take effect in docker. |
Ok, I'll tackle from moby/moby#33408 then. Thanks! |
@benturner There are two parts to it: you need the template expansion implemented in swarmkit and then there needs to be a executor code to call that in moby. |
Got it, thanks. So now once this gets merged into swarmkit how do I pull the template change into moby? |
@benturner: You don't need to wait for it to be merged to pull the change into moby. You can change the swarmkit line in moby's
And then run |
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.
This also needs to parameterize the driver opts, as was requested in the original issue.
Hrm, where does that code live? |
@benturner It is on the same structure you are templating, the |
07a90e1
to
f9b7a40
Compare
@stevvooe I added the driver-opt support, please take another look? Thanks. |
f9b7a40
to
06fa563
Compare
Signed-off-by: Ben Turner <bent@silklabs.com>
06fa563
to
01b18a7
Compare
@aaronlehmann @stevvooe so after playing around with this a little I think we may have a problem... @fcrisciani and I discussed this a bit from the Then there's the added complexity that some templated aliases will be consistent across all tasks (e.g. Thoughts? Directions? I'm a bit at sea here... |
I'm not sure I understand what problem templating network aliases is solving. It might help answer your questions if you can give a few example use cases. |
My primary motivation is moby/moby#33408 (comment) but @mark-church wanted something for |
@aaronlehmann Do we not have the concept of a per-task alias? That might be the hang up here. If the templating is not task-specific, then it doesn't make a lot of sense. |
@stevvooe @aaronlehmann in libnetwork we have already:
|
Per-task aliases exist in |
@benturner aliases for service in the form of --network-opt was introduced by #2176 . The aliases were service aliases per network the service was connected to. From what I understood from the requirement the templating support was to be added for --network-opt which takes in network name , alias (service alias) and driver options per network. |
Sure, but that basically leaves us with the problems I outlined in #2250 (comment) right? |
@stevvooe @aaronlehmann how should I proceed here? |
For per-task aliases, I think the Docker CLI would need to have something like the
Doesn't the container get both the default name/alias, and the custom alias? Or is the problem that libnetwork service discovery wouldn't return the custom aliases (so they're only usable if you know the alias). |
Closes #2249
@stevvooe am I on the right track here? Networks aren't part of the ContainerSpec so I think I have to do it this way... Obviously this needs tests but 'd like some guidance before I commit to this path. Thanks.