Skip to content

Conversation

akerouanton
Copy link
Member

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)

Constants for both platform-specific and platform-independent networks
are added to the api/network package.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
@@ -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
Copy link
Member

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 🤔)

Copy link
Member Author

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 ;

Copy link
Member Author

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?

Copy link
Member

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 named transparent (or nat) 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
Copy link
Member

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.

Copy link
Member

@thaJeztah thaJeztah left a 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)

@thaJeztah thaJeztah merged commit ce1ee98 into moby:master Nov 24, 2023
@thaJeztah thaJeztah added this to the 25.0.0 milestone Nov 24, 2023
@thaJeztah thaJeztah added the area/api API label Nov 24, 2023
@akerouanton akerouanton deleted the api-predefined-networks branch November 24, 2023 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api API kind/refactor PR's that refactor, or clean-up code status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants