mirror of https://github.com/docker/cli.git
Handle networks.driver_opts for a service
These are endpoint-specific driver options... services: myservice: image: myimage networks: mynet: driver_opts: "option1": "value1" The API has had support for a long time, it's only recently been added to compose (unreleased right now). Signed-off-by: Rob Murray <rob.murray@docker.com>
This commit is contained in:
parent
a731722652
commit
94f9de5928
|
@ -215,16 +215,19 @@ func convertServiceNetworks(
|
|||
return nil, errors.Errorf("undefined network %q", networkName)
|
||||
}
|
||||
var aliases []string
|
||||
var driverOpts map[string]string
|
||||
if network != nil {
|
||||
aliases = network.Aliases
|
||||
driverOpts = network.DriverOpts
|
||||
}
|
||||
target := namespace.Scope(networkName)
|
||||
if networkConfig.Name != "" {
|
||||
target = networkConfig.Name
|
||||
}
|
||||
netAttachConfig := swarm.NetworkAttachmentConfig{
|
||||
Target: target,
|
||||
Aliases: aliases,
|
||||
Target: target,
|
||||
Aliases: aliases,
|
||||
DriverOpts: driverOpts,
|
||||
}
|
||||
// Only add default aliases to user defined networks. Other networks do
|
||||
// not support aliases.
|
||||
|
|
|
@ -240,6 +240,10 @@ func TestConvertServiceNetworks(t *testing.T) {
|
|||
networks := map[string]*composetypes.ServiceNetworkConfig{
|
||||
"front": {
|
||||
Aliases: []string{"something"},
|
||||
DriverOpts: map[string]string{
|
||||
"driver.opt1": "optval1",
|
||||
"driver.opt2": "optval2",
|
||||
},
|
||||
},
|
||||
"back": {
|
||||
Aliases: []string{"other"},
|
||||
|
@ -257,6 +261,10 @@ func TestConvertServiceNetworks(t *testing.T) {
|
|||
{
|
||||
Target: "fronttier",
|
||||
Aliases: []string{"something", "service"},
|
||||
DriverOpts: map[string]string{
|
||||
"driver.opt1": "optval1",
|
||||
"driver.opt2": "optval2",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -207,6 +207,9 @@ services:
|
|||
aliases:
|
||||
- alias1
|
||||
- alias3
|
||||
driver_opts:
|
||||
"driveropt1": "optval1"
|
||||
"driveropt2": "optval2"
|
||||
other-network:
|
||||
ipv4_address: 172.16.238.10
|
||||
ipv6_address: 2001:3984:3989::10
|
||||
|
|
|
@ -190,6 +190,10 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
|
|||
Aliases: []string{"alias1", "alias3"},
|
||||
Ipv4Address: "",
|
||||
Ipv6Address: "",
|
||||
DriverOpts: map[string]string{
|
||||
"driveropt1": "optval1",
|
||||
"driveropt2": "optval2",
|
||||
},
|
||||
},
|
||||
"other-network": {
|
||||
Ipv4Address: "172.16.238.10",
|
||||
|
|
|
@ -285,7 +285,11 @@
|
|||
"aliases": [
|
||||
"alias1",
|
||||
"alias3"
|
||||
]
|
||||
],
|
||||
"driver_opts": {
|
||||
"driveropt1": "optval1",
|
||||
"driveropt2": "optval2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"pid": "host",
|
||||
|
|
|
@ -152,6 +152,9 @@ services:
|
|||
aliases:
|
||||
- alias1
|
||||
- alias3
|
||||
driver_opts:
|
||||
driveropt1: optval1
|
||||
driveropt2: optval2
|
||||
pid: host
|
||||
ports:
|
||||
- mode: ingress
|
||||
|
|
|
@ -197,6 +197,12 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"aliases": {"$ref": "#/definitions/list_of_strings"},
|
||||
"driver_opts": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^.+$": { "type": ["string", "number"] }
|
||||
}
|
||||
},
|
||||
"ipv4_address": {"type": "string"},
|
||||
"ipv6_address": {"type": "string"}
|
||||
},
|
||||
|
|
|
@ -374,9 +374,10 @@ type PlacementPreferences struct {
|
|||
|
||||
// ServiceNetworkConfig is the network configuration for a service
|
||||
type ServiceNetworkConfig struct {
|
||||
Aliases []string `yaml:",omitempty" json:"aliases,omitempty"`
|
||||
Ipv4Address string `mapstructure:"ipv4_address" yaml:"ipv4_address,omitempty" json:"ipv4_address,omitempty"`
|
||||
Ipv6Address string `mapstructure:"ipv6_address" yaml:"ipv6_address,omitempty" json:"ipv6_address,omitempty"`
|
||||
Aliases []string `yaml:",omitempty" json:"aliases,omitempty"`
|
||||
DriverOpts map[string]string `mapstructure:"driver_opts" yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
|
||||
Ipv4Address string `mapstructure:"ipv4_address" yaml:"ipv4_address,omitempty" json:"ipv4_address,omitempty"`
|
||||
Ipv6Address string `mapstructure:"ipv6_address" yaml:"ipv6_address,omitempty" json:"ipv6_address,omitempty"`
|
||||
}
|
||||
|
||||
// ServicePortConfig is the port configuration for a service
|
||||
|
|
Loading…
Reference in New Issue