Adds volume support to container recipe factory

This commit is contained in:
benbierens 2023-09-07 08:19:19 +02:00
parent a03d9cd92f
commit aa3e500a58
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 33 additions and 5 deletions

View File

@ -29,7 +29,10 @@ namespace DistTestCore.Codex
AddExposedPortAndVar("CODEX_API_PORT");
AddEnvVar("CODEX_API_BINDADDR", "0.0.0.0");
AddEnvVar("CODEX_DATA_DIR", $"datadir{ContainerNumber}");
var dataDir = $"datadir{ContainerNumber}";
AddEnvVar("CODEX_DATA_DIR", dataDir);
AddVolume(dataDir);
AddInternalPortAndVar("CODEX_DISC_PORT", DiscoveryPortTag);
AddEnvVar("CODEX_LOG_LEVEL", config.LogLevel.ToString()!.ToUpperInvariant());

View File

@ -2,7 +2,7 @@
{
public class ContainerRecipe
{
public ContainerRecipe(int number, string image, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, object[] additionals)
public ContainerRecipe(int number, string image, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, object[] additionals)
{
Number = number;
Image = image;
@ -11,6 +11,7 @@
EnvVars = envVars;
PodLabels = podLabels;
PodAnnotations = podAnnotations;
Volumes = volumes;
Additionals = additionals;
}
@ -22,6 +23,7 @@
public EnvVar[] EnvVars { get; }
public PodLabels PodLabels { get; }
public PodAnnotations PodAnnotations { get; }
public VolumeMount[] Volumes { get; }
public object[] Additionals { get; }
public Port GetPortByTag(string tag)
@ -34,7 +36,8 @@
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))}, ";
$"envVars: {string.Join(",", EnvVars.Select(v => v.Name + ":" + v.Value))}, " +
$"volumes: {string.Join(",", Volumes.Select(v => $"'{v.MountPath}'"))}";
}
}
@ -61,4 +64,16 @@
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; }
}
}

View File

@ -7,6 +7,7 @@
private readonly List<EnvVar> envVars = new List<EnvVar>();
private readonly PodLabels podLabels = new PodLabels();
private readonly PodAnnotations podAnnotations = new PodAnnotations();
private readonly List<VolumeMount> volumeMounts = new List<VolumeMount>();
private readonly List<object> additionals = new List<object>();
private RecipeComponentFactory factory = null!;
@ -20,10 +21,11 @@
var recipe = new ContainerRecipe(containerNumber, Image,
exposedPorts.ToArray(),
internalPorts.ToArray(),
envVars.ToArray(),
internalPorts.ToArray(),
envVars.ToArray(),
podLabels.Clone(),
podAnnotations.Clone(),
volumeMounts.ToArray(),
additionals.ToArray());
exposedPorts.Clear();
@ -31,6 +33,7 @@
envVars.Clear();
podLabels.Clear();
podAnnotations.Clear();
volumeMounts.Clear();
additionals.Clear();
this.factory = null!;
@ -94,6 +97,13 @@
podAnnotations.Add(name, value);
}
protected void AddVolume(string mountPath)
{
volumeMounts.Add(new VolumeMount(
$"autovolume-{Guid.NewGuid().ToString().ToLowerInvariant()}",
mountPath));
}
protected void Additional(object userData)
{
additionals.Add(userData);