-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
run, create, connect: add support for gw-priority #5664
Conversation
edc8ee0
to
1b4418b
Compare
@@ -23,6 +23,7 @@ type connectOptions struct { | |||
aliases []string | |||
linklocalips []string | |||
driverOpts []string | |||
gwPriority int |
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'm probably a bit late realising, but should this have been a uint, or do we expect negative values to be ok? 🙈
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 an int on purpose as it allows to set the priority to a negative value when some existing endpoints have the default priority 0
set. @robmry wrote about that here: moby/moby#48936 (comment)
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.
But wasn't higher higher priority, so if I want a new network to become the default, I need to give it a higher priority?
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.
Absolutely. But if one of the current network give you a default gateway, and you want to stick with it, you can connect new networks with a negative priority.
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.
(mostly considering if it's zero, then I did not consider it a priority (and alphabetic order is used), and only if I would explicitly want a network to take priority, I'd probably set a non-zero value; any value lower (including zero) would not take priority in that case)
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.
You might consider priority of existing endpoints only when you connect a new network. In that case, having the ability to set a negative priority gives you a way to not touch the existing endpoint(s), but still get the behavior you want.
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.
Yeah, I'm good with this for now; perhaps we should brainstorm next week to see if there's still things to be done here.
- default network (say
ddd
) withoutgw_priority
; this becomes the default gateway - connect to other network (say
ccc
) withoutgw_priority
; this sorts beforeddd
, so now takes over default gateway - ☝️ this is current situation, and potentially problematic, as it's implicit / unexpected
- 👉 so, say, I don't want that to happen, I now set
gw_priority=-999
to make sure it doesn't capture the gateway - But now I connect to another network,
aaa
. I don't want that to take over the default gateway, so I setgw_priority=-999
. - But
-999
was already set forccc
, so those are now "same priority", except for name. ⚠️ if I would to connect another network (saybbb
), but do NOT set agw_priority
, it would takeover the default gateway fromddd
(as those both have0
priority)
So, yes, there's some more controls here, but it's also shifting the goal-posts, and we may now end up with something similar to z-index
or oomscore-adjust
; "let's pick a high enough value" or "low enough value" that probably no other network has picked. Or at least, these numbers will become rather complicated to use, without either
- "pick a low or high enough value" hoping no other network was given that value
- or knowing what values were given to other networks and pick that value "+1" or "-1"
- or keep track of values used, and continue incrementing or decrementing
I think at least we should consider setting a limit (which could be same as oom-score-adjust, e.g. -999 - 999
); not sure if we need the whole range of +/- MAXINT32.
But perhaps we need to look at some other logic as well; I think in most cases, I'd expect the gateway to not change unless I want it to (i.e., once it's set, connecting another network should not change it, unless I want that new one to take over); almost considering if some of the enumerating could be handled daemon-side ("put me first, shift others one position down"), but that would mostly be for connecting to an existing container (for "create container with multiple networks", I could see a more declarative aproach being good).
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5664 +/- ##
=======================================
Coverage 59.53% 59.53%
=======================================
Files 346 346
Lines 29356 29365 +9
=======================================
+ Hits 17477 17483 +6
- Misses 10909 10911 +2
- Partials 970 971 +1 |
cli/command/network/connect.go
Outdated
@@ -55,6 +56,7 @@ func newConnectCommand(dockerCLI command.Cli) *cobra.Command { | |||
flags.StringSliceVar(&options.aliases, "alias", []string{}, "Add network-scoped alias for the container") | |||
flags.StringSliceVar(&options.linklocalips, "link-local-ip", []string{}, "Add a link-local address for the container") | |||
flags.StringSliceVar(&options.driverOpts, "driver-opt", []string{}, "driver options for the network") | |||
flags.IntVar(&options.gwPriority, "gw-priority", 0, "Used to determine which network provides the default gateway") |
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'd be nice to say it's the highest priority number that wins (it's not obvious, "priority 1" sounds important!). But, it's tricky without writing an essay. How about ...
flags.IntVar(&options.gwPriority, "gw-priority", 0, "Used to determine which network provides the default gateway") | |
flags.IntVar(&options.gwPriority, "gw-priority", 0, "Highest gw-priority provides the default gateway") |
| `mac-address` | `--mac-address` | Container MAC address (e.g., 92:d0:c6:0a:29:33) | | ||
| `link-local-ip` | `--link-local-ip` | Container IPv4/IPv6 link-local addresses | | ||
| `driver-opt` | `docker network connect --driver-opt` | Network driver options | | ||
| `gw-priority` | | Used to determine which network should provide the default gateway. | |
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'd be good to say it's the highest priority number that gets the default gw here too (and in the network_connect.md
) ... but, with a bit more space to play with, these could also say the priority can be negative?
opts/network.go
Outdated
case gwPriorityOpt: | ||
netOpt.GwPriority, err = strconv.Atoi(val) | ||
if err != nil { | ||
return fmt.Errorf("invalid priority: %w", err) |
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.
return fmt.Errorf("invalid priority: %w", err) | |
return fmt.Errorf("invalid gw-priority: %w", err) |
Signed-off-by: Albin Kerouanton <[email protected]>
1b4418b
to
d4db289
Compare
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
Related to:
- What I did
This adds support for the newly introduced
GwPriority
API field. It can be set on bothdocker container run
anddocker network connect
.For the
run
command, it's made available only through the extended syntax.- How I did it
- How to verify it
CI is green.
- Description for the changelog