cs-codex-dist-tests/KubernetesWorkflow/ContainerResources.cs

53 lines
1.4 KiB
C#
Raw Normal View History

2023-09-08 08:14:52 +00:00
using Utils;
namespace KubernetesWorkflow
{
2023-09-08 11:47:49 +00:00
public class ContainerResources
2023-09-08 08:14:52 +00:00
{
2023-09-08 11:47:49 +00:00
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)
2023-09-08 08:14:52 +00:00
{
MilliCPUs = milliCPUs;
Memory = memory;
}
2023-09-08 11:47:49 +00:00
public ContainerResourceSet(int milliCPUs)
2023-09-08 08:14:52 +00:00
: this(milliCPUs, new ByteSize(0))
{
}
2023-09-08 11:47:49 +00:00
public ContainerResourceSet(ByteSize memory)
2023-09-08 08:14:52 +00:00
: this(0, memory)
{
}
2023-09-08 11:47:49 +00:00
public ContainerResourceSet()
2023-09-08 08:14:52 +00:00
: this(0)
{
}
public int MilliCPUs { get; }
public ByteSize Memory { get; }
public override string ToString()
{
var result = new List<string>();
if (MilliCPUs == 0) result.Add("cpu: unlimited");
else result.Add($"cpu: {MilliCPUs} milliCPUs");
if (Memory.SizeInBytes == 0) result.Add("memory: unlimited");
else result.Add($"memory: {Memory}");
return string.Join(", ", result);
}
}
}