2
0
mirror of synced 2025-01-12 17:44:08 +00:00

43 lines
1.5 KiB
C#
Raw Normal View History

2023-04-25 11:31:15 +02:00
using Logging;
using Utils;
namespace KubernetesWorkflow
2023-04-12 13:53:55 +02:00
{
public class WorkflowCreator
{
private readonly NumberSource numberSource = new NumberSource(0);
2023-04-13 11:07:36 +02:00
private readonly NumberSource containerNumberSource = new NumberSource(0);
private readonly KnownK8sPods knownPods = new KnownK8sPods();
private readonly K8sCluster cluster;
2023-09-12 10:31:55 +02:00
private readonly ILog log;
private readonly Configuration configuration;
private readonly string k8sNamespace;
public WorkflowCreator(ILog log, Configuration configuration)
{
2023-04-25 11:31:15 +02:00
this.log = log;
this.configuration = configuration;
cluster = new K8sCluster(configuration);
k8sNamespace = configuration.KubernetesNamespace.ToLowerInvariant();
}
2023-04-12 13:53:55 +02:00
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
2023-04-12 13:53:55 +02:00
{
2023-04-13 11:07:36 +02:00
var workflowNumberSource = new WorkflowNumberSource(numberSource.GetNextNumber(),
containerNumberSource);
return new StartupWorkflow(log, workflowNumberSource, cluster, knownPods, GetNamespace(namespaceOverride));
}
private string GetNamespace(string? namespaceOverride)
{
if (namespaceOverride != null)
{
if (!configuration.AllowNamespaceOverride) throw new Exception("Namespace override is not allowed.");
return namespaceOverride;
}
return k8sNamespace;
2023-04-12 13:53:55 +02:00
}
}
}