From c3e346cb2f3f5068a6c77ed168fd9b16200e4c55 Mon Sep 17 00:00:00 2001 From: Piotr Krakowski <50808402+madpeteguy@users.noreply.github.com> Date: Sun, 17 Jul 2022 21:26:50 +0200 Subject: [PATCH] Enable game server ip address allocation for macvlan driver. 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. --- environment/docker/container.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/environment/docker/container.go b/environment/docker/container.go index 8f059638..432a1240 100644 --- a/environment/docker/container.go +++ b/environment/docker/container.go @@ -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" @@ -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") }