Nicer deployment names.
This commit is contained in:
parent
fb7488769d
commit
f7c69d6f24
@ -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
|
||||||
|
@ -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; }
|
||||||
|
@ -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(),
|
||||||
|
@ -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)
|
||||||
|
19
KubernetesWorkflow/K8sNameUtils.cs
Normal file
19
KubernetesWorkflow/K8sNameUtils.cs
Normal 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('-');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user