Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public class AgentKnobs
new EnvironmentKnobSource("AGENT_DOCKER_MTU_VALUE"),
new BuiltInDefaultKnobSource(string.Empty));

public static readonly Knob DockerNetworkCreateDriver = new Knob(
nameof(DockerNetworkCreateDriver),
"Allow to specify which driver will be used when creating docker network",
new EnvironmentKnobSource("AZP_AGENT_DOCKER_NETWORK_CREATE_DRIVER"),
new BuiltInDefaultKnobSource(string.Empty));

// Directory structure
public static readonly Knob AgentToolsDirectory = new Knob(
nameof(AgentToolsDirectory),
Expand Down
29 changes: 22 additions & 7 deletions src/Agent.Worker/Container/DockerCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,33 @@ public async Task<int> DockerNetworkCreate(IExecutionContext context, string net
var usingWindowsContainers = context.Containers.Where(x => x.ExecutionOS != PlatformUtil.OS.Windows).Count() == 0;
var networkDrivers = await ExecuteDockerCommandAsync(context, "info", "-f \"{{range .Plugins.Network}}{{println .}}{{end}}\"");
var valueMTU = AgentKnobs.MTUValueForContainerJobs.GetValue(_knobContext).AsString();
var driver = AgentKnobs.DockerNetworkCreateDriver.GetValue(_knobContext).AsString();
string optionMTU = "";

if (!String.IsNullOrEmpty(valueMTU)) {

if (!String.IsNullOrEmpty(valueMTU))
{
optionMTU = $"-o \"com.docker.network.driver.mtu={valueMTU}\"";
}
}

if (usingWindowsContainers && networkDrivers.Contains("nat"))
string options = $"create --label {DockerInstanceLabel} {network} {optionMTU}";

if (!String.IsNullOrEmpty(driver))
{
if (networkDrivers.Contains(driver))
{
options += $" --driver {driver}";
}
else
{
Trace.Warning($"Specified '{driver}' driver not found!");
}
}
else if (usingWindowsContainers && networkDrivers.Contains("nat"))
{
return await ExecuteDockerCommandAsync(context, "network", $"create --label {DockerInstanceLabel} {network} {optionMTU} --driver nat", context.CancellationToken);
options += $" --driver nat";
}

return await ExecuteDockerCommandAsync(context, "network", $"create --label {DockerInstanceLabel} {network} {optionMTU}", context.CancellationToken);
return await ExecuteDockerCommandAsync(context, "network", options, context.CancellationToken);
}

public async Task<int> DockerNetworkRemove(IExecutionContext context, string network)
Expand Down Expand Up @@ -420,4 +435,4 @@ await processInvoker.ExecuteAsync(
return output;
}
}
}
}