Skip to content

Commit

Permalink
Merge pull request #5125 from robmry/stack_deploy_service_driver_opts
Browse files Browse the repository at this point in the history
Handle networks.driver_opts for a service
  • Loading branch information
laurazard authored Jun 7, 2024
2 parents a5058b8 + 94f9de5 commit 482bf86
Show file tree
Hide file tree
Showing 11 changed files with 719 additions and 13 deletions.
7 changes: 5 additions & 2 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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",
},
},
}

Expand Down
5 changes: 4 additions & 1 deletion cli/compose/loader/full-example.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.12"
version: "3.13"

services:
foo:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion cli/compose/loader/full-struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func fullExampleConfig(workingDir, homeDir string) *types.Config {
return &types.Config{
Version: "3.12",
Version: "3.13",
Services: services(workingDir, homeDir),
Networks: networks(),
Volumes: volumes(),
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func strPtr(val string) *string {
}

var sampleConfig = types.Config{
Version: "3.12",
Version: "3.13",
Services: []types.ServiceConfig{
{
Name: "foo",
Expand Down
8 changes: 6 additions & 2 deletions cli/compose/loader/testdata/full-example.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@
"aliases": [
"alias1",
"alias3"
]
],
"driver_opts": {
"driveropt1": "optval1",
"driveropt2": "optval2"
}
}
},
"pid": "host",
Expand Down Expand Up @@ -509,7 +513,7 @@
"working_dir": "/code"
}
},
"version": "3.12",
"version": "3.13",
"volumes": {
"another-volume": {
"name": "user_specified_name",
Expand Down
5 changes: 4 additions & 1 deletion cli/compose/loader/testdata/full-example.yaml.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.12"
version: "3.13"
services:
foo:
build:
Expand Down Expand Up @@ -152,6 +152,9 @@ services:
aliases:
- alias1
- alias3
driver_opts:
driveropt1: optval1
driveropt2: optval2
pid: host
ports:
- mode: ingress
Expand Down
Loading

0 comments on commit 482bf86

Please sign in to comment.