-
Notifications
You must be signed in to change notification settings - Fork 18.8k
api: Add consts for predefined networks #46447
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
Conversation
Constants for both platform-specific and platform-independent networks are added to the api/network package. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
cacb321
to
a8975c9
Compare
@@ -25,11 +27,11 @@ func (i Isolation) IsValid() bool { | |||
// NetworkName returns the name of the network stack. | |||
func (n NetworkMode) NetworkName() string { | |||
if n.IsDefault() { | |||
return "default" | |||
return network.NetworkDefault |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
network
package ; - They're used in other places than just this package ;
NetworkMode
is about the main network of a container, these consts aren't related to containers ;
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.
@thaJeztah Are you still on the fence on that?
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.
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=default
work?) - 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
bridge
on 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=default
work?)
Answering myself: it doesn't
docker network create --driver=default hellonetwork
Error response from daemon: plugin "default" not found
@@ -10,15 +12,15 @@ func (i Isolation) IsValid() bool { | |||
// NetworkName returns the name of the network stack. | |||
func (n NetworkMode) NetworkName() string { | |||
if n.IsBridge() { | |||
return "bridge" | |||
return network.NetworkBridge |
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 whole function makes me weep.
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.
"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)