Skip to content

Commit

Permalink
Set endpoint-specific DriverOpts
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Murray <rob.murray@docker.com>
  • Loading branch information
robmry authored and glours committed May 22, 2024
1 parent 663866c commit 048fd13
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ func createEndpointSettings(p *types.Project, service types.ServiceConfig, servi
ipv4Address string
ipv6Address string
macAddress string
driverOpts types.Options
)
if config != nil {
ipv4Address = config.Ipv4Address
Expand All @@ -449,6 +450,7 @@ func createEndpointSettings(p *types.Project, service types.ServiceConfig, servi
LinkLocalIPs: config.LinkLocalIPs,
}
macAddress = config.MacAddress
driverOpts = config.DriverOpts
}
return &network.EndpointSettings{
Aliases: getAliases(p, service, serviceIndex, networkKey, useNetworkAliases),
Expand All @@ -457,6 +459,7 @@ func createEndpointSettings(p *types.Project, service types.ServiceConfig, servi
IPv6Gateway: ipv6Address,
IPAMConfig: ipam,
MacAddress: macAddress,
DriverOpts: driverOpts,
}
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/compose/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"gotest.tools/v3/assert/cmp"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/docker/api/types/network"

composetypes "github.com/compose-spec/compose-go/v2/types"
moby "github.com/docker/docker/api/types"
Expand Down Expand Up @@ -275,3 +276,54 @@ func TestDefaultNetworkSettings(t *testing.T) {
assert.Check(t, cmp.Nil(networkConfig))
})
}

func TestCreateEndpointSettings(t *testing.T) {
eps := createEndpointSettings(
&composetypes.Project{
Name: "projName",
},
composetypes.ServiceConfig{
Name: "serviceName",
ContainerName: "containerName",
Networks: map[string]*composetypes.ServiceNetworkConfig{
"netName": {
Priority: 100,
Aliases: []string{"alias1", "alias2"},
Ipv4Address: "10.16.17.18",
Ipv6Address: "fdb4:7a7f:373a:3f0c::42",
LinkLocalIPs: []string{"169.254.10.20"},
MacAddress: "10:00:00:00:01",
DriverOpts: composetypes.Options{
"driverOpt1": "optval1",
"driverOpt2": "optval2",
},
},
},
},
0, // serviceIndex
"netName", // networkKey
[]string{"link1", "link2"}, // links
true, // useNetworkAliases
)
assert.Check(t, cmp.DeepEqual(eps, &network.EndpointSettings{
IPAMConfig: &network.EndpointIPAMConfig{
IPv4Address: "10.16.17.18",
IPv6Address: "fdb4:7a7f:373a:3f0c::42",
LinkLocalIPs: []string{"169.254.10.20"},
},
Links: []string{"link1", "link2"},
Aliases: []string{"containerName", "serviceName", "alias1", "alias2"},
MacAddress: "10:00:00:00:01",
DriverOpts: map[string]string{
"driverOpt1": "optval1",
"driverOpt2": "optval2",
},

// FIXME(robmry) - IPAddress and IPv6Gateway are "operational data" fields...
// - The IPv6 address here is the container's address, not the gateway.
// - Both fields will be cleared by the daemon, but they could be removed from
// the request.
IPAddress: "10.16.17.18",
IPv6Gateway: "fdb4:7a7f:373a:3f0c::42",
}))
}

0 comments on commit 048fd13

Please sign in to comment.