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

80 lines
2.4 KiB
C#
Raw Normal View History

2023-04-12 11:53:55 +00:00
namespace KubernetesWorkflow
{
public class ContainerRecipe
{
public ContainerRecipe(int number, string image, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, object[] additionals)
2023-04-12 11:53:55 +00:00
{
Number = number;
2023-04-12 11:53:55 +00:00
Image = image;
ExposedPorts = exposedPorts;
InternalPorts = internalPorts;
EnvVars = envVars;
PodLabels = podLabels;
PodAnnotations = podAnnotations;
Volumes = volumes;
2023-04-14 10:37:05 +00:00
Additionals = additionals;
2023-04-12 11:53:55 +00:00
}
public string Name { get { return $"ctnr{Number}"; } }
public int Number { get; }
2023-04-12 11:53:55 +00:00
public string Image { get; }
public Port[] ExposedPorts { get; }
public Port[] InternalPorts { get; }
public EnvVar[] EnvVars { get; }
public PodLabels PodLabels { get; }
public PodAnnotations PodAnnotations { get; }
public VolumeMount[] Volumes { get; }
2023-04-14 10:37:05 +00:00
public object[] Additionals { get; }
2023-04-13 12:36:17 +00:00
public Port GetPortByTag(string tag)
{
return ExposedPorts.Concat(InternalPorts).Single(p => p.Tag == tag);
}
public override string ToString()
{
return $"(container-recipe: {Name}, image: {Image}, " +
$"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))}, " +
$"volumes: {string.Join(",", Volumes.Select(v => $"'{v.MountPath}'"))}";
}
2023-04-12 11:53:55 +00:00
}
public class Port
{
2023-04-13 12:36:17 +00:00
public Port(int number, string tag)
2023-04-12 11:53:55 +00:00
{
Number = number;
2023-04-13 12:36:17 +00:00
Tag = tag;
2023-04-12 11:53:55 +00:00
}
public int Number { get; }
2023-04-13 12:36:17 +00:00
public string Tag { get; }
2023-04-12 11:53:55 +00:00
}
public class EnvVar
{
public EnvVar(string name, string value)
{
Name = name;
Value = value;
}
public string Name { get; }
public string Value { get; }
}
public class VolumeMount
{
public VolumeMount(string volumeName, string mountPath)
{
VolumeName = volumeName;
MountPath = mountPath;
}
public string VolumeName { get; }
public string MountPath { get; }
}
2023-04-12 11:53:55 +00:00
}