Skip to content

Commit 482bf86

Browse files
authored
Merge pull request docker#5125 from robmry/stack_deploy_service_driver_opts
Handle networks.driver_opts for a service
2 parents a5058b8 + 94f9de5 commit 482bf86

11 files changed

+719
-13
lines changed

cli/compose/convert/service.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,19 @@ func convertServiceNetworks(
215215
return nil, errors.Errorf("undefined network %q", networkName)
216216
}
217217
var aliases []string
218+
var driverOpts map[string]string
218219
if network != nil {
219220
aliases = network.Aliases
221+
driverOpts = network.DriverOpts
220222
}
221223
target := namespace.Scope(networkName)
222224
if networkConfig.Name != "" {
223225
target = networkConfig.Name
224226
}
225227
netAttachConfig := swarm.NetworkAttachmentConfig{
226-
Target: target,
227-
Aliases: aliases,
228+
Target: target,
229+
Aliases: aliases,
230+
DriverOpts: driverOpts,
228231
}
229232
// Only add default aliases to user defined networks. Other networks do
230233
// not support aliases.

cli/compose/convert/service_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ func TestConvertServiceNetworks(t *testing.T) {
240240
networks := map[string]*composetypes.ServiceNetworkConfig{
241241
"front": {
242242
Aliases: []string{"something"},
243+
DriverOpts: map[string]string{
244+
"driver.opt1": "optval1",
245+
"driver.opt2": "optval2",
246+
},
243247
},
244248
"back": {
245249
Aliases: []string{"other"},
@@ -257,6 +261,10 @@ func TestConvertServiceNetworks(t *testing.T) {
257261
{
258262
Target: "fronttier",
259263
Aliases: []string{"something", "service"},
264+
DriverOpts: map[string]string{
265+
"driver.opt1": "optval1",
266+
"driver.opt2": "optval2",
267+
},
260268
},
261269
}
262270

cli/compose/loader/full-example.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.12"
1+
version: "3.13"
22

33
services:
44
foo:
@@ -207,6 +207,9 @@ services:
207207
aliases:
208208
- alias1
209209
- alias3
210+
driver_opts:
211+
"driveropt1": "optval1"
212+
"driveropt2": "optval2"
210213
other-network:
211214
ipv4_address: 172.16.238.10
212215
ipv6_address: 2001:3984:3989::10

cli/compose/loader/full-struct_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func fullExampleConfig(workingDir, homeDir string) *types.Config {
1313
return &types.Config{
14-
Version: "3.12",
14+
Version: "3.13",
1515
Services: services(workingDir, homeDir),
1616
Networks: networks(),
1717
Volumes: volumes(),
@@ -190,6 +190,10 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
190190
Aliases: []string{"alias1", "alias3"},
191191
Ipv4Address: "",
192192
Ipv6Address: "",
193+
DriverOpts: map[string]string{
194+
"driveropt1": "optval1",
195+
"driveropt2": "optval2",
196+
},
193197
},
194198
"other-network": {
195199
Ipv4Address: "172.16.238.10",

cli/compose/loader/loader_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func strPtr(val string) *string {
184184
}
185185

186186
var sampleConfig = types.Config{
187-
Version: "3.12",
187+
Version: "3.13",
188188
Services: []types.ServiceConfig{
189189
{
190190
Name: "foo",

cli/compose/loader/testdata/full-example.json.golden

+6-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@
285285
"aliases": [
286286
"alias1",
287287
"alias3"
288-
]
288+
],
289+
"driver_opts": {
290+
"driveropt1": "optval1",
291+
"driveropt2": "optval2"
292+
}
289293
}
290294
},
291295
"pid": "host",
@@ -509,7 +513,7 @@
509513
"working_dir": "/code"
510514
}
511515
},
512-
"version": "3.12",
516+
"version": "3.13",
513517
"volumes": {
514518
"another-volume": {
515519
"name": "user_specified_name",

cli/compose/loader/testdata/full-example.yaml.golden

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.12"
1+
version: "3.13"
22
services:
33
foo:
44
build:
@@ -152,6 +152,9 @@ services:
152152
aliases:
153153
- alias1
154154
- alias3
155+
driver_opts:
156+
driveropt1: optval1
157+
driveropt2: optval2
155158
pid: host
156159
ports:
157160
- mode: ingress

0 commit comments

Comments
 (0)