Include request resource sets.
This commit is contained in:
parent
9d2dbbbcab
commit
75b16bd2ca
@ -17,11 +17,13 @@ namespace DistTestCore.Codex
|
||||
|
||||
public override string AppName => "codex";
|
||||
public override string Image { get; }
|
||||
protected override ResourceLimits ResourceLimits => new ResourceLimits(milliCPUs: 250, memory: 512.MB());
|
||||
|
||||
|
||||
public CodexContainerRecipe()
|
||||
{
|
||||
Image = GetDockerImage();
|
||||
|
||||
Resources.Requests = new ContainerResourceSet(milliCPUs: 250, memory: 512.MB());
|
||||
Resources.Limits = new ContainerResourceSet(milliCPUs: 1000, memory: 2.GB());
|
||||
}
|
||||
|
||||
protected override void InitializeRecipe(StartupConfig startupConfig)
|
||||
|
@ -2,11 +2,11 @@
|
||||
{
|
||||
public class ContainerRecipe
|
||||
{
|
||||
public ContainerRecipe(int number, string image, ResourceLimits resourceLimits, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, object[] additionals)
|
||||
public ContainerRecipe(int number, string image, ContainerResources resources, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, object[] additionals)
|
||||
{
|
||||
Number = number;
|
||||
Image = image;
|
||||
ResourceLimits = resourceLimits;
|
||||
Resources = resources;
|
||||
ExposedPorts = exposedPorts;
|
||||
InternalPorts = internalPorts;
|
||||
EnvVars = envVars;
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
public string Name { get { return $"ctnr{Number}"; } }
|
||||
public int Number { get; }
|
||||
public ResourceLimits ResourceLimits { get; }
|
||||
public ContainerResources Resources { get; }
|
||||
public string Image { get; }
|
||||
public Port[] ExposedPorts { get; }
|
||||
public Port[] InternalPorts { get; }
|
||||
@ -39,7 +39,7 @@
|
||||
$"exposedPorts: {string.Join(",", ExposedPorts.Select(p => p.Number))}, " +
|
||||
$"internalPorts: {string.Join(",", InternalPorts.Select(p => p.Number))}, " +
|
||||
$"envVars: {string.Join(",", EnvVars.Select(v => v.Name + ":" + v.Value))}, " +
|
||||
$"limits: {ResourceLimits}, " +
|
||||
$"limits: {Resources}, " +
|
||||
$"volumes: {string.Join(",", Volumes.Select(v => $"'{v.MountPath}'"))}";
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace KubernetesWorkflow
|
||||
|
||||
Initialize(config);
|
||||
|
||||
var recipe = new ContainerRecipe(containerNumber, Image, ResourceLimits,
|
||||
var recipe = new ContainerRecipe(containerNumber, Image, Resources,
|
||||
exposedPorts.ToArray(),
|
||||
internalPorts.ToArray(),
|
||||
envVars.ToArray(),
|
||||
@ -44,9 +44,9 @@ namespace KubernetesWorkflow
|
||||
|
||||
public abstract string AppName { get; }
|
||||
public abstract string Image { get; }
|
||||
public ContainerResources Resources { get; } = new ContainerResources();
|
||||
protected int ContainerNumber { get; private set; } = 0;
|
||||
protected int Index { get; private set; } = 0;
|
||||
protected virtual ResourceLimits ResourceLimits { get; } = new ResourceLimits();
|
||||
protected abstract void Initialize(StartupConfig config);
|
||||
|
||||
protected Port AddExposedPort(string tag = "")
|
||||
|
@ -2,25 +2,36 @@
|
||||
|
||||
namespace KubernetesWorkflow
|
||||
{
|
||||
public class ResourceLimits
|
||||
public class ContainerResources
|
||||
{
|
||||
public ResourceLimits(int milliCPUs, ByteSize memory)
|
||||
public ContainerResourceSet Requests { get; set; } = new ContainerResourceSet();
|
||||
public ContainerResourceSet Limits { get; set; } = new ContainerResourceSet();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"requests:{Requests}, limits:{Limits}";
|
||||
}
|
||||
}
|
||||
|
||||
public class ContainerResourceSet
|
||||
{
|
||||
public ContainerResourceSet(int milliCPUs, ByteSize memory)
|
||||
{
|
||||
MilliCPUs = milliCPUs;
|
||||
Memory = memory;
|
||||
}
|
||||
|
||||
public ResourceLimits(int milliCPUs)
|
||||
public ContainerResourceSet(int milliCPUs)
|
||||
: this(milliCPUs, new ByteSize(0))
|
||||
{
|
||||
}
|
||||
|
||||
public ResourceLimits(ByteSize memory)
|
||||
public ContainerResourceSet(ByteSize memory)
|
||||
: this(0, memory)
|
||||
{
|
||||
}
|
||||
|
||||
public ResourceLimits()
|
||||
public ContainerResourceSet()
|
||||
: this(0)
|
||||
{
|
||||
}
|
@ -432,20 +432,21 @@ namespace KubernetesWorkflow
|
||||
{
|
||||
return new V1ResourceRequirements
|
||||
{
|
||||
Limits = CreateResourceLimit(recipe.ResourceLimits)
|
||||
Requests = CreateResourceQuantities(recipe.Resources.Requests),
|
||||
Limits = CreateResourceQuantities(recipe.Resources.Limits)
|
||||
};
|
||||
}
|
||||
|
||||
private Dictionary<string, ResourceQuantity> CreateResourceLimit(ResourceLimits limits)
|
||||
private Dictionary<string, ResourceQuantity> CreateResourceQuantities(ContainerResourceSet set)
|
||||
{
|
||||
var result = new Dictionary<string, ResourceQuantity>();
|
||||
if (limits.MilliCPUs != 0)
|
||||
if (set.MilliCPUs != 0)
|
||||
{
|
||||
result.Add("cpu", new ResourceQuantity($"{limits.MilliCPUs}m"));
|
||||
result.Add("cpu", new ResourceQuantity($"{set.MilliCPUs}m"));
|
||||
}
|
||||
if (limits.Memory.SizeInBytes != 0)
|
||||
if (set.Memory.SizeInBytes != 0)
|
||||
{
|
||||
result.Add("memory", new ResourceQuantity(limits.Memory.ToSuffixNotation()));
|
||||
result.Add("memory", new ResourceQuantity(set.Memory.ToSuffixNotation()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user