Skip to content

Commit

Permalink
Enable game server ip address allocation for macvlan driver.
Browse files Browse the repository at this point in the history
Issue:
For macvlan driver default docker config assign first available ip.
Game servers get ip assigned in order of container creation.

Solution proposal:
Wings support only one docker network for each game server.
To assign correct IP default allocation could be used.
Allocations doesn't limit IPs at all, admin could set desired game server container ip and port by default allocation.
  • Loading branch information
madpeteguy committed Oct 7, 2022
1 parent 058f643 commit 8bc3820
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion environment/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,18 @@ func (e *Environment) Create() error {
UsernsMode: container.UsernsMode(config.Get().Docker.UsernsMode),
}

if _, err := e.client.ContainerCreate(ctx, conf, hostConf, nil, nil, e.Id); err != nil {
var netConf *network.NetworkingConfig = nil //In case when no networking config is needed set nil
if "macvlan" == config.Get().Docker.Network.Driver { //Generate networking config for macvlan driver
netConf = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
config.Get().Docker.Network.Name: { //Get network name from wings config
IPAddress: e.Config().Allocations().DefaultMapping.Ip, //Use default mapping ip address (wings support only one network per server)
},
},
}
}
// Pass the networkings configuration or nil if none required
if _, err := e.client.ContainerCreate(ctx, conf, hostConf, netConf, nil, e.Id); err != nil {
return errors.Wrap(err, "environment/docker: failed to create container")
}

Expand Down

0 comments on commit 8bc3820

Please sign in to comment.