diff --git a/DistTestCore/Codex/CodexContainerRecipe.cs b/DistTestCore/Codex/CodexContainerRecipe.cs index aa67789..1b03a50 100644 --- a/DistTestCore/Codex/CodexContainerRecipe.cs +++ b/DistTestCore/Codex/CodexContainerRecipe.cs @@ -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()); diff --git a/KubernetesWorkflow/ContainerRecipe.cs b/KubernetesWorkflow/ContainerRecipe.cs index e3bd7b8..f58c3fd 100644 --- a/KubernetesWorkflow/ContainerRecipe.cs +++ b/KubernetesWorkflow/ContainerRecipe.cs @@ -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; } + } } diff --git a/KubernetesWorkflow/ContainerRecipeFactory.cs b/KubernetesWorkflow/ContainerRecipeFactory.cs index 2c64efb..f10d062 100644 --- a/KubernetesWorkflow/ContainerRecipeFactory.cs +++ b/KubernetesWorkflow/ContainerRecipeFactory.cs @@ -7,6 +7,7 @@ private readonly List envVars = new List(); private readonly PodLabels podLabels = new PodLabels(); private readonly PodAnnotations podAnnotations = new PodAnnotations(); + private readonly List volumeMounts = new List(); private readonly List additionals = new List(); 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);