2
0
mirror of synced 2025-02-02 19:53:29 +00:00

Nicer deployment names.

This commit is contained in:
ThatBen 2023-09-15 12:25:10 +02:00
parent fb7488769d
commit f7c69d6f24
6 changed files with 41 additions and 18 deletions

View File

@ -30,6 +30,12 @@ namespace Core
workflow.DownloadContainerLog(container, logHandler, tailLines); workflow.DownloadContainerLog(container, logHandler, tailLines);
return logHandler.DownloadLog(); return logHandler.DownloadLog();
} }
public string ExecuteContainerCommand(RunningContainer container, string command, params string[] args)
{
var workflow = entryPoint.Tools.CreateWorkflow();
return workflow.ExecuteCommand(container, command, args);
}
} }
public interface IHasContainer public interface IHasContainer

View File

@ -2,9 +2,10 @@
{ {
public class ContainerRecipe public class ContainerRecipe
{ {
public ContainerRecipe(int number, string image, ContainerResources resources, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, object[] additionals) public ContainerRecipe(int number, string? nameOverride, string image, ContainerResources resources, Port[] exposedPorts, Port[] internalPorts, EnvVar[] envVars, PodLabels podLabels, PodAnnotations podAnnotations, VolumeMount[] volumes, object[] additionals)
{ {
Number = number; Number = number;
NameOverride = nameOverride;
Image = image; Image = image;
Resources = resources; Resources = resources;
ExposedPorts = exposedPorts; ExposedPorts = exposedPorts;
@ -14,10 +15,20 @@
PodAnnotations = podAnnotations; PodAnnotations = podAnnotations;
Volumes = volumes; Volumes = volumes;
Additionals = additionals; Additionals = additionals;
if (NameOverride != null)
{
Name = $"{K8sNameUtils.Format(NameOverride)}-{Number}";
}
else
{
Name = $"ctnr{Number}";
}
} }
public string Name { get { return $"ctnr{Number}"; } } public string Name { get; }
public int Number { get; } public int Number { get; }
public string? NameOverride { get; }
public ContainerResources Resources { get; } public ContainerResources Resources { get; }
public string Image { get; } public string Image { get; }
public Port[] ExposedPorts { get; } public Port[] ExposedPorts { get; }

View File

@ -21,7 +21,7 @@ namespace KubernetesWorkflow
Initialize(config); Initialize(config);
var recipe = new ContainerRecipe(containerNumber, Image, Resources, var recipe = new ContainerRecipe(containerNumber, config.NameOverride, Image, Resources,
exposedPorts.ToArray(), exposedPorts.ToArray(),
internalPorts.ToArray(), internalPorts.ToArray(),
envVars.ToArray(), envVars.ToArray(),

View File

@ -399,7 +399,7 @@ namespace KubernetesWorkflow
{ {
return new V1ObjectMeta return new V1ObjectMeta
{ {
Name = "deploy-" + workflowNumberSource.WorkflowNumber, Name = string.Join('-',containerRecipes.Select(r => r.Name)),
NamespaceProperty = K8sNamespace, NamespaceProperty = K8sNamespace,
Labels = GetSelector(containerRecipes), Labels = GetSelector(containerRecipes),
Annotations = GetAnnotations(containerRecipes) Annotations = GetAnnotations(containerRecipes)

View File

@ -0,0 +1,19 @@
namespace KubernetesWorkflow
{
public static class K8sNameUtils
{
public static string Format(string s)
{
var result = s.ToLowerInvariant()
.Replace(" ", "-")
.Replace(":", "-")
.Replace("/", "-")
.Replace("\\", "-")
.Replace("[", "-")
.Replace("]", "-")
.Replace(",", "-");
return result.Trim('-');
}
}
}

View File

@ -6,7 +6,7 @@
public void Add(string key, string value) public void Add(string key, string value)
{ {
labels.Add(key, Format(value)); labels.Add(key, K8sNameUtils.Format(value));
} }
public PodLabels Clone() public PodLabels Clone()
@ -21,19 +21,6 @@
labels.Clear(); labels.Clear();
} }
private static string Format(string s)
{
var result = s.ToLowerInvariant()
.Replace(":", "-")
.Replace("/", "-")
.Replace("\\", "-")
.Replace("[", "-")
.Replace("]", "-")
.Replace(",", "-");
return result.Trim('-');
}
internal Dictionary<string, string> GetLabels() internal Dictionary<string, string> GetLabels()
{ {
return labels; return labels;