Update FindNetwork to address network name duplications#30897
Update FindNetwork to address network name duplications#30897yongtang merged 2 commits intomoby:masterfrom
FindNetwork to address network name duplications#30897Conversation
api/server/router/network/backend.go
Outdated
There was a problem hiding this comment.
Change to networkID to enforcing the usage of ID instead of Name/ID/Prefix
There was a problem hiding this comment.
It is a lot easier to enforcing non-ambiguity here.
There was a problem hiding this comment.
Non-ambiguity at the api level.
There was a problem hiding this comment.
Pass nw.ID() for connect.
There was a problem hiding this comment.
Pass nw.ID() for disconnect.
There was a problem hiding this comment.
Delete might happen in both local and scoped networks.
There was a problem hiding this comment.
This findNetwork is different from daemon.FindNetwork as it will be cross scopes (both local and swarm).
There was a problem hiding this comment.
Could you make this comment a docstring (above the function) ? Right now it looks like it's documenting the variables inside the function.
Also what do you think about findUniqueNetwork() as a name?
There was a problem hiding this comment.
Thanks @dnephin. The comment has been updated to doc string. The name has also been changed.
There was a problem hiding this comment.
The networks() is returning the name only, which should not be encouraged (should always use ID if possible).
daemon/container_operations.go
Outdated
There was a problem hiding this comment.
Alway try to use NetworkID whenever NetworkID is available.
There was a problem hiding this comment.
This name is a bit odd (from just the name, I would expect it to always return an ID), not a big thing because it's not exported, but perhaps we should find a better name for it
daemon/network.go
Outdated
There was a problem hiding this comment.
In case of swarm networks, we have to allow creation even if a local network with the same name already exist.
9c44301 to
7c4538f
Compare
|
The Jenkins failure seems real. Will spend time to investigate it. |
FindNetwork to address network name duplicationsFindNetwork to address network name duplications
5666f16 to
a2bfaab
Compare
FindNetwork to address network name duplicationsFindNetwork to address network name duplications
|
All tests passed now. |
dnephin
left a comment
There was a problem hiding this comment.
There seem to be a bunch of changes to DeleteNetwork.
Could you give more of an explanation of what this changes, and why it fixes the problem?
There was a problem hiding this comment.
Should these be defer, and called immediately after the create for each?
There was a problem hiding this comment.
Thanks. The PR has been updated.
a2bfaab to
7295c58
Compare
|
Thanks @dnephin for the review. The goal of this PR is to try to address the issue caused by name duplication in network names. Previously, the network name is unique so some of the implementation uses will look up the network name (instead of network ID) when needed. However, later on the flag Adding swarm network in, the same network name could appears in either However, in the existing implementation, many places uses That causes issues:
This PR tries to address the issue mentioned by always avoid |
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
31421e6 to
b249ccb
Compare
| case len(listByFullName) == 1: | ||
| return listByFullName[0], nil | ||
| case len(listByFullName) > 1: | ||
| return nil, fmt.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName)) |
There was a problem hiding this comment.
We should not be using fmt.Errorf for these errors.
There was a problem hiding this comment.
@cpuguy83 Sorry, that was probably due to the multiple rebase/conflict that was overlooked. Let me take a look and have a fix for it.
There was a problem hiding this comment.
No worries. I've got it fixed in my errdefs or.
| // to provide network specific functionality. | ||
| type Backend interface { | ||
| FindNetwork(idName string) (libnetwork.Network, error) | ||
| FindUniqueNetwork(idName string) (libnetwork.Network, error) |
There was a problem hiding this comment.
I wonder if we should've kept the old name here (FindNetwork); the issue being resolved here is a bugfix, so I don't see a real reason to rename the function (in general, I'd expect a function like this to return a unique network, so not sure a change in naming is really needed)
@yongtang @vdemeester wdyt?
- What I did
This fix is part of the effort to address #30242 (comment) where issue arise when creating services because of the fact that multiple networks may share the same name (within or across local/swarm scopes).
- How I did it
The focus of this fix is to allow creation of service when a network in local scope has the same name as the service network.
- How to verify it
An integration test has been added.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
This fix is related to #30242.
Signed-off-by: Yong Tang yong.tang.github@outlook.com