better service names

This commit is contained in:
benbierens 2023-11-03 14:53:27 +01:00
parent 438c4271e1
commit 19d466d5d6
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 10 additions and 3 deletions

View File

@ -564,7 +564,7 @@ namespace KubernetesWorkflow
var serviceSpec = new V1Service
{
ApiVersion = "v1",
Metadata = CreateServiceMetadata(),
Metadata = CreateServiceMetadata(containerRecipes),
Spec = new V1ServiceSpec
{
Type = "NodePort",
@ -614,11 +614,18 @@ namespace KubernetesWorkflow
client.Run(c => c.DeleteNamespacedService(serviceName, K8sNamespace));
}
private V1ObjectMeta CreateServiceMetadata()
private V1ObjectMeta CreateServiceMetadata(ContainerRecipe[] containerRecipes)
{
var exposedRecipe = containerRecipes.FirstOrDefault(c => c.ExposedPorts.Any());
var name = "service-" + workflowNumberSource.WorkflowNumber;
if (exposedRecipe != null)
{
name = K8sNameUtils.Format(exposedRecipe.Name) + "-" + workflowNumberSource.WorkflowNumber;
}
return new V1ObjectMeta
{
Name = "service-" + workflowNumberSource.WorkflowNumber,
Name = name,
NamespaceProperty = K8sNamespace
};
}