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 9, 2022
1 parent 058f643 commit c3e346c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion environment/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/client"
"github.com/docker/docker/daemon/logger/local"
"github.com/docker/docker/api/types/network"

"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/environment"
Expand Down Expand Up @@ -264,7 +265,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 c3e346c

Please sign in to comment.