api: Add consts for predefined networks#46447
Conversation
Constants for both platform-specific and platform-independent networks are added to the api/network package. Signed-off-by: Albin Kerouanton <[email protected]>
cacb321 to
a8975c9
Compare
| func (n NetworkMode) NetworkName() string { | ||
| if n.IsDefault() { | ||
| return "default" | ||
| return network.NetworkDefault |
There was a problem hiding this comment.
Would it make sense to define the types in this package? (Given that NetworkMode is also defined here 🤔)
There was a problem hiding this comment.
I went back and forth and I couldn't find any prevailing argument. But here's my final reasoning on that:
- These consts are about predefined networks. As a client user, I'd expect networking stuff, including consts for predefined networks, to be defined in the
networkpackage ; - They're used in other places than just this package ;
NetworkModeis about the main network of a container, these consts aren't related to containers ;
There was a problem hiding this comment.
@thaJeztah Are you still on the fence on that?
There was a problem hiding this comment.
Are you still on the fence on that?
Yeah, probably shouldn't block the PR though.
It's just very messy because
- we conflated "mode" and "network-names" (which was intentional, but implementation of that wasn't great in hindsight)
- "default" is horrible, or more specifically, horrible because it's used in some places, but may not work in other places, which also relates to the above (does
docker network create --driver=defaultwork?) - for places where we're currently checking for "names" ("modes"), we should more look at properties of the network (is this network "attachable", does it support "x", can it be "created" / instantiated?)
- we still need to look at making some checks platform-independent; i.e. we should probably not allow creating a network named
bridgeon Windows, or vice-versa, a network namedtransparent(ornat) on Linux. We currently define some reserved names based on the platform the daemon is running on, but I think we should make those a general "reserved names" (or something like that)
(does
docker network create --driver=defaultwork?)
Answering myself: it doesn't
docker network create --driver=default hellonetwork
Error response from daemon: plugin "default" not found| func (n NetworkMode) NetworkName() string { | ||
| if n.IsBridge() { | ||
| return "bridge" | ||
| return network.NetworkBridge |
There was a problem hiding this comment.
This whole function makes me weep.
thaJeztah
left a comment
There was a problem hiding this comment.
"LGTM"
but we should really start looking if we can clean up this mess (see my comments)
Related to:
- What I did
Constants for both platform-specific and platform-independent networks are added to the api/network package.
- A picture of a cute animal (not mandatory but encouraged)