run, create, connect: add support for gw-priority
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
parent
5afa739692
commit
d4db289eb5
@ -858,7 +858,9 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
epConfig := &networktypes.EndpointSettings{}
|
epConfig := &networktypes.EndpointSettings{
|
||||||
|
GwPriority: ep.GwPriority,
|
||||||
|
}
|
||||||
epConfig.Aliases = append(epConfig.Aliases, ep.Aliases...)
|
epConfig.Aliases = append(epConfig.Aliases, ep.Aliases...)
|
||||||
if len(ep.DriverOpts) > 0 {
|
if len(ep.DriverOpts) > 0 {
|
||||||
epConfig.DriverOpts = make(map[string]string)
|
epConfig.DriverOpts = make(map[string]string)
|
||||||
|
@ -23,6 +23,7 @@ type connectOptions struct {
|
|||||||
aliases []string
|
aliases []string
|
||||||
linklocalips []string
|
linklocalips []string
|
||||||
driverOpts []string
|
driverOpts []string
|
||||||
|
gwPriority int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConnectCommand(dockerCLI command.Cli) *cobra.Command {
|
func newConnectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||||
@ -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.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.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.StringSliceVar(&options.driverOpts, "driver-opt", []string{}, "driver options for the network")
|
||||||
|
flags.IntVar(&options.gwPriority, "gw-priority", 0, "Highest gw-priority provides the default gateway. Accepts positive and negative values.")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +75,7 @@ func runConnect(ctx context.Context, apiClient client.NetworkAPIClient, options
|
|||||||
Links: options.links.GetAll(),
|
Links: options.links.GetAll(),
|
||||||
Aliases: options.aliases,
|
Aliases: options.aliases,
|
||||||
DriverOpts: driverOpts,
|
DriverOpts: driverOpts,
|
||||||
|
GwPriority: options.gwPriority,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ func TestNetworkConnectWithFlags(t *testing.T) {
|
|||||||
"driveropt1": "optval1,optval2",
|
"driveropt1": "optval1,optval2",
|
||||||
"driveropt2": "optval4",
|
"driveropt2": "optval4",
|
||||||
},
|
},
|
||||||
|
GwPriority: 100,
|
||||||
}
|
}
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
|
networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
|
||||||
@ -76,6 +77,7 @@ func TestNetworkConnectWithFlags(t *testing.T) {
|
|||||||
{"ip6", "fdef:f401:8da0:1234::5678"},
|
{"ip6", "fdef:f401:8da0:1234::5678"},
|
||||||
{"link", "otherctr"},
|
{"link", "otherctr"},
|
||||||
{"link-local-ip", "169.254.42.42"},
|
{"link-local-ip", "169.254.42.42"},
|
||||||
|
{"gw-priority", "100"},
|
||||||
} {
|
} {
|
||||||
err := cmd.Flags().Set(opt.name, opt.value)
|
err := cmd.Flags().Set(opt.name, opt.value)
|
||||||
assert.Check(t, err)
|
assert.Check(t, err)
|
||||||
|
@ -750,7 +750,7 @@ for the `--network` flag. Comma-separated options that can be specified in the e
|
|||||||
`--network` syntax are:
|
`--network` syntax are:
|
||||||
|
|
||||||
| Option | Top-level Equivalent | Description |
|
| Option | Top-level Equivalent | Description |
|
||||||
|-----------------|---------------------------------------|-------------------------------------------------|
|
|-----------------|---------------------------------------|-----------------------------------------------------------------------------------------|
|
||||||
| `name` | | The name of the network (mandatory) |
|
| `name` | | The name of the network (mandatory) |
|
||||||
| `alias` | `--network-alias` | Add network-scoped alias for the container |
|
| `alias` | `--network-alias` | Add network-scoped alias for the container |
|
||||||
| `ip` | `--ip` | IPv4 address (e.g., 172.30.100.104) |
|
| `ip` | `--ip` | IPv4 address (e.g., 172.30.100.104) |
|
||||||
@ -758,6 +758,7 @@ for the `--network` flag. Comma-separated options that can be specified in the e
|
|||||||
| `mac-address` | `--mac-address` | Container MAC address (e.g., 92:d0:c6:0a:29:33) |
|
| `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 |
|
| `link-local-ip` | `--link-local-ip` | Container IPv4/IPv6 link-local addresses |
|
||||||
| `driver-opt` | `docker network connect --driver-opt` | Network driver options |
|
| `driver-opt` | `docker network connect --driver-opt` | Network driver options |
|
||||||
|
| `gw-priority` | | Highest gw-priority provides the default gateway. Accepts positive and negative values. |
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ docker network create --subnet 192.0.2.0/24 my-net1
|
$ docker network create --subnet 192.0.2.0/24 my-net1
|
||||||
|
@ -6,9 +6,10 @@ Connect a container to a network
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|:--------------------|:--------------|:--------|:-------------------------------------------|
|
|:--------------------|:--------------|:--------|:----------------------------------------------------------------------------------------|
|
||||||
| [`--alias`](#alias) | `stringSlice` | | Add network-scoped alias for the container |
|
| [`--alias`](#alias) | `stringSlice` | | Add network-scoped alias for the container |
|
||||||
| `--driver-opt` | `stringSlice` | | driver options for the network |
|
| `--driver-opt` | `stringSlice` | | driver options for the network |
|
||||||
|
| `--gw-priority` | `int` | `0` | Highest gw-priority provides the default gateway. Accepts positive and negative values. |
|
||||||
| [`--ip`](#ip) | `string` | | IPv4 address (e.g., `172.30.100.104`) |
|
| [`--ip`](#ip) | `string` | | IPv4 address (e.g., `172.30.100.104`) |
|
||||||
| `--ip6` | `string` | | IPv6 address (e.g., `2001:db8::33`) |
|
| `--ip6` | `string` | | IPv6 address (e.g., `2001:db8::33`) |
|
||||||
| [`--link`](#link) | `list` | | Add link to another container |
|
| [`--link`](#link) | `list` | | Add link to another container |
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ const (
|
|||||||
networkOptMacAddress = "mac-address"
|
networkOptMacAddress = "mac-address"
|
||||||
networkOptLinkLocalIP = "link-local-ip"
|
networkOptLinkLocalIP = "link-local-ip"
|
||||||
driverOpt = "driver-opt"
|
driverOpt = "driver-opt"
|
||||||
|
gwPriorityOpt = "gw-priority"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NetworkAttachmentOpts represents the network options for endpoint creation
|
// NetworkAttachmentOpts represents the network options for endpoint creation
|
||||||
@ -28,6 +30,7 @@ type NetworkAttachmentOpts struct {
|
|||||||
IPv6Address string
|
IPv6Address string
|
||||||
LinkLocalIPs []string
|
LinkLocalIPs []string
|
||||||
MacAddress string
|
MacAddress string
|
||||||
|
GwPriority int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkOpt represents a network config in swarm mode.
|
// NetworkOpt represents a network config in swarm mode.
|
||||||
@ -83,6 +86,11 @@ func (n *NetworkOpt) Set(value string) error { //nolint:gocyclo
|
|||||||
netOpt.DriverOpts = make(map[string]string)
|
netOpt.DriverOpts = make(map[string]string)
|
||||||
}
|
}
|
||||||
netOpt.DriverOpts[key] = val
|
netOpt.DriverOpts[key] = val
|
||||||
|
case gwPriorityOpt:
|
||||||
|
netOpt.GwPriority, err = strconv.Atoi(val)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid gw-priority: %w", err)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return errors.New("invalid field key " + key)
|
return errors.New("invalid field key " + key)
|
||||||
}
|
}
|
||||||
|
@ -112,6 +112,16 @@ func TestNetworkOptAdvancedSyntax(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
value: "name=docknet1,gw-priority=10",
|
||||||
|
expected: []NetworkAttachmentOpts{
|
||||||
|
{
|
||||||
|
Target: "docknet1",
|
||||||
|
Aliases: []string{},
|
||||||
|
GwPriority: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.value, func(t *testing.T) {
|
t.Run(tc.value, func(t *testing.T) {
|
||||||
|
@ -13,7 +13,7 @@ require (
|
|||||||
github.com/distribution/reference v0.6.0
|
github.com/distribution/reference v0.6.0
|
||||||
github.com/docker/cli-docs-tool v0.8.0
|
github.com/docker/cli-docs-tool v0.8.0
|
||||||
github.com/docker/distribution v2.8.3+incompatible
|
github.com/docker/distribution v2.8.3+incompatible
|
||||||
github.com/docker/docker v27.0.2-0.20241120142749-e5c2b5e10d68+incompatible // master (v-next)
|
github.com/docker/docker v27.0.2-0.20241202115249-87fbd9cd3b37+incompatible // master (v-next)
|
||||||
github.com/docker/docker-credential-helpers v0.8.2
|
github.com/docker/docker-credential-helpers v0.8.2
|
||||||
github.com/docker/go-connections v0.5.0
|
github.com/docker/go-connections v0.5.0
|
||||||
github.com/docker/go-units v0.5.0
|
github.com/docker/go-units v0.5.0
|
||||||
|
@ -51,8 +51,8 @@ github.com/docker/cli-docs-tool v0.8.0/go.mod h1:8TQQ3E7mOXoYUs811LiPdUnAhXrcVsB
|
|||||||
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||||
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
|
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
|
||||||
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||||
github.com/docker/docker v27.0.2-0.20241120142749-e5c2b5e10d68+incompatible h1:ZWh4HhdUCagAd3S+gsFPOobHbc562obYFSrz3irGSsU=
|
github.com/docker/docker v27.0.2-0.20241202115249-87fbd9cd3b37+incompatible h1:Ct0/s+pkUCDPBsQmLVHnBEas8OlTRxNvDXdSa6Y2PfE=
|
||||||
github.com/docker/docker v27.0.2-0.20241120142749-e5c2b5e10d68+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
github.com/docker/docker v27.0.2-0.20241202115249-87fbd9cd3b37+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||||
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
|
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
|
||||||
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
|
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
|
||||||
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=
|
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=
|
||||||
|
11
vendor/github.com/docker/docker/api/swagger.yaml
generated
vendored
11
vendor/github.com/docker/docker/api/swagger.yaml
generated
vendored
@ -2927,6 +2927,16 @@ definitions:
|
|||||||
example:
|
example:
|
||||||
com.example.some-label: "some-value"
|
com.example.some-label: "some-value"
|
||||||
com.example.some-other-label: "some-other-value"
|
com.example.some-other-label: "some-other-value"
|
||||||
|
GwPriority:
|
||||||
|
description: |
|
||||||
|
This property determines which endpoint will provide the default
|
||||||
|
gateway for a container. The endpoint with the highest priority will
|
||||||
|
be used. If multiple endpoints have the same priority, endpoints are
|
||||||
|
lexicographically sorted based on their network name, and the one
|
||||||
|
that sorts first is picked.
|
||||||
|
type: "number"
|
||||||
|
example:
|
||||||
|
- 10
|
||||||
|
|
||||||
# Operational data
|
# Operational data
|
||||||
NetworkID:
|
NetworkID:
|
||||||
@ -10910,6 +10920,7 @@ paths:
|
|||||||
IPv4Address: "172.24.56.89"
|
IPv4Address: "172.24.56.89"
|
||||||
IPv6Address: "2001:db8::5689"
|
IPv6Address: "2001:db8::5689"
|
||||||
MacAddress: "02:42:ac:12:05:02"
|
MacAddress: "02:42:ac:12:05:02"
|
||||||
|
Priority: 100
|
||||||
tags: ["Network"]
|
tags: ["Network"]
|
||||||
|
|
||||||
/networks/{id}/disconnect:
|
/networks/{id}/disconnect:
|
||||||
|
1
vendor/github.com/docker/docker/api/types/network/endpoint.go
generated
vendored
1
vendor/github.com/docker/docker/api/types/network/endpoint.go
generated
vendored
@ -19,6 +19,7 @@ type EndpointSettings struct {
|
|||||||
// generated address).
|
// generated address).
|
||||||
MacAddress string
|
MacAddress string
|
||||||
DriverOpts map[string]string
|
DriverOpts map[string]string
|
||||||
|
GwPriority int
|
||||||
// Operational data
|
// Operational data
|
||||||
NetworkID string
|
NetworkID string
|
||||||
EndpointID string
|
EndpointID string
|
||||||
|
1
vendor/github.com/docker/docker/registry/service.go
generated
vendored
1
vendor/github.com/docker/docker/registry/service.go
generated
vendored
@ -103,7 +103,6 @@ func (s *Service) ResolveRepository(name reference.Named) (*RepositoryInfo, erro
|
|||||||
type APIEndpoint struct {
|
type APIEndpoint struct {
|
||||||
Mirror bool
|
Mirror bool
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
Version APIVersion // Deprecated: v1 registries are deprecated, and endpoints are always v2.
|
|
||||||
AllowNondistributableArtifacts bool
|
AllowNondistributableArtifacts bool
|
||||||
Official bool
|
Official bool
|
||||||
TrimHostname bool
|
TrimHostname bool
|
||||||
|
4
vendor/github.com/docker/docker/registry/service_v2.go
generated
vendored
4
vendor/github.com/docker/docker/registry/service_v2.go
generated
vendored
@ -25,7 +25,6 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e
|
|||||||
}
|
}
|
||||||
endpoints = append(endpoints, APIEndpoint{
|
endpoints = append(endpoints, APIEndpoint{
|
||||||
URL: mirrorURL,
|
URL: mirrorURL,
|
||||||
Version: APIVersion2, //nolint:staticcheck // ignore SA1019 (Version is deprecated) to allow potential consumers to transition.
|
|
||||||
Mirror: true,
|
Mirror: true,
|
||||||
TrimHostname: true,
|
TrimHostname: true,
|
||||||
TLSConfig: mirrorTLSConfig,
|
TLSConfig: mirrorTLSConfig,
|
||||||
@ -33,7 +32,6 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e
|
|||||||
}
|
}
|
||||||
endpoints = append(endpoints, APIEndpoint{
|
endpoints = append(endpoints, APIEndpoint{
|
||||||
URL: DefaultV2Registry,
|
URL: DefaultV2Registry,
|
||||||
Version: APIVersion2, //nolint:staticcheck // ignore SA1019 (Version is deprecated) to allow potential consumers to transition.
|
|
||||||
Official: true,
|
Official: true,
|
||||||
TrimHostname: true,
|
TrimHostname: true,
|
||||||
TLSConfig: tlsconfig.ServerDefault(),
|
TLSConfig: tlsconfig.ServerDefault(),
|
||||||
@ -55,7 +53,6 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e
|
|||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Host: hostname,
|
Host: hostname,
|
||||||
},
|
},
|
||||||
Version: APIVersion2, //nolint:staticcheck // ignore SA1019 (Version is deprecated) to allow potential consumers to transition.
|
|
||||||
AllowNondistributableArtifacts: ana,
|
AllowNondistributableArtifacts: ana,
|
||||||
TrimHostname: true,
|
TrimHostname: true,
|
||||||
TLSConfig: tlsConfig,
|
TLSConfig: tlsConfig,
|
||||||
@ -68,7 +65,6 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e
|
|||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: hostname,
|
Host: hostname,
|
||||||
},
|
},
|
||||||
Version: APIVersion2, //nolint:staticcheck // ignore SA1019 (Version is deprecated) to allow potential consumers to transition.
|
|
||||||
AllowNondistributableArtifacts: ana,
|
AllowNondistributableArtifacts: ana,
|
||||||
TrimHostname: true,
|
TrimHostname: true,
|
||||||
// used to check if supposed to be secure via InsecureSkipVerify
|
// used to check if supposed to be secure via InsecureSkipVerify
|
||||||
|
23
vendor/github.com/docker/docker/registry/types.go
generated
vendored
23
vendor/github.com/docker/docker/registry/types.go
generated
vendored
@ -5,27 +5,6 @@ import (
|
|||||||
"github.com/docker/docker/api/types/registry"
|
"github.com/docker/docker/api/types/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
// APIVersion is an integral representation of an API version (presently
|
|
||||||
// either 1 or 2)
|
|
||||||
//
|
|
||||||
// Deprecated: v1 registries are deprecated, and endpoints are always v2.
|
|
||||||
type APIVersion int
|
|
||||||
|
|
||||||
func (av APIVersion) String() string {
|
|
||||||
return apiVersions[av]
|
|
||||||
}
|
|
||||||
|
|
||||||
// API Version identifiers.
|
|
||||||
const (
|
|
||||||
APIVersion1 APIVersion = 1 // Deprecated: v1 registries are deprecated, and endpoints are always v2.
|
|
||||||
APIVersion2 APIVersion = 2 // Deprecated: v1 registries are deprecated, and endpoints are always v2.
|
|
||||||
)
|
|
||||||
|
|
||||||
var apiVersions = map[APIVersion]string{
|
|
||||||
APIVersion1: "v1",
|
|
||||||
APIVersion2: "v2",
|
|
||||||
}
|
|
||||||
|
|
||||||
// RepositoryInfo describes a repository
|
// RepositoryInfo describes a repository
|
||||||
type RepositoryInfo struct {
|
type RepositoryInfo struct {
|
||||||
Name reference.Named
|
Name reference.Named
|
||||||
@ -37,5 +16,7 @@ type RepositoryInfo struct {
|
|||||||
Official bool
|
Official bool
|
||||||
// Class represents the class of the repository, such as "plugin"
|
// Class represents the class of the repository, such as "plugin"
|
||||||
// or "image".
|
// or "image".
|
||||||
|
//
|
||||||
|
// Deprecated: this field is no longer used, and will be removed in the next release.
|
||||||
Class string
|
Class string
|
||||||
}
|
}
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -55,7 +55,7 @@ github.com/docker/distribution/registry/client/transport
|
|||||||
github.com/docker/distribution/registry/storage/cache
|
github.com/docker/distribution/registry/storage/cache
|
||||||
github.com/docker/distribution/registry/storage/cache/memory
|
github.com/docker/distribution/registry/storage/cache/memory
|
||||||
github.com/docker/distribution/uuid
|
github.com/docker/distribution/uuid
|
||||||
# github.com/docker/docker v27.0.2-0.20241120142749-e5c2b5e10d68+incompatible
|
# github.com/docker/docker v27.0.2-0.20241202115249-87fbd9cd3b37+incompatible
|
||||||
## explicit
|
## explicit
|
||||||
github.com/docker/docker/api
|
github.com/docker/docker/api
|
||||||
github.com/docker/docker/api/types
|
github.com/docker/docker/api/types
|
||||||
|
Loading…
x
Reference in New Issue
Block a user