Adds internal ports to container-port array as long as they have tags.

This commit is contained in:
benbierens 2023-10-23 14:05:08 +02:00
parent 5a021a4bfe
commit 58816430e3
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 15 additions and 3 deletions

View File

@ -46,6 +46,7 @@ namespace KubernetesWorkflow
{
return containerPort.InternalAddress;
}
if (containerPort.ExternalAddress == Address.InvalidAddress) throw new Exception($"Getting address by tag {portTag} resulted in an invalid address.");
return containerPort.ExternalAddress;
}
}

View File

@ -146,6 +146,16 @@ namespace KubernetesWorkflow
GetContainerExternalAddress(pod, servicePorts, exposedPort),
GetContainerInternalAddress(exposedPort)));
}
foreach (var internalPort in recipe.InternalPorts)
{
if (!string.IsNullOrEmpty(internalPort.Tag))
{
result.Add(new ContainerPort(
internalPort,
Address.InvalidAddress,
GetContainerInternalAddress(internalPort)));
}
}
return result.ToArray();
}
@ -159,14 +169,13 @@ namespace KubernetesWorkflow
servicePort.Number);
}
private Address GetContainerInternalAddress(Port exposedPort)
private Address GetContainerInternalAddress(Port port)
{
var serviceName = "service-" + numberSource.WorkflowNumber;
var port = exposedPort.Number;
return new Address(
$"http://{serviceName}.{k8sNamespace}.svc.cluster.local",
port);
port.Number);
}
private ContainerRecipe[] CreateRecipes(int numberOfContainers, ContainerRecipeFactory recipeFactory, StartupConfig startupConfig)

View File

@ -2,6 +2,8 @@
{
public class Address
{
public static readonly Address InvalidAddress = new Address(string.Empty, 0);
public Address(string host, int port)
{
Host = host;