2023-04-25 09:31:15 +00:00
|
|
|
|
using Logging;
|
|
|
|
|
using Utils;
|
2023-04-12 13:11:36 +00:00
|
|
|
|
|
|
|
|
|
namespace KubernetesWorkflow
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
|
|
|
|
public class WorkflowCreator
|
|
|
|
|
{
|
2023-04-12 13:11:36 +00:00
|
|
|
|
private readonly NumberSource numberSource = new NumberSource(0);
|
2023-04-13 09:07:36 +00:00
|
|
|
|
private readonly NumberSource containerNumberSource = new NumberSource(0);
|
2023-04-12 13:22:09 +00:00
|
|
|
|
private readonly K8sCluster cluster;
|
2023-09-12 08:31:55 +00:00
|
|
|
|
private readonly ILog log;
|
2023-09-13 12:37:53 +00:00
|
|
|
|
private readonly Configuration configuration;
|
2023-09-12 12:50:18 +00:00
|
|
|
|
private readonly string k8sNamespace;
|
2023-04-12 13:22:09 +00:00
|
|
|
|
|
2023-09-12 12:50:18 +00:00
|
|
|
|
public WorkflowCreator(ILog log, Configuration configuration)
|
2023-04-12 13:22:09 +00:00
|
|
|
|
{
|
2023-04-25 09:31:15 +00:00
|
|
|
|
this.log = log;
|
2023-09-13 12:37:53 +00:00
|
|
|
|
this.configuration = configuration;
|
2023-09-12 12:50:18 +00:00
|
|
|
|
cluster = new K8sCluster(configuration);
|
|
|
|
|
k8sNamespace = configuration.KubernetesNamespace.ToLowerInvariant();
|
2023-04-12 13:22:09 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
2023-09-13 12:37:53 +00:00
|
|
|
|
public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null)
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-04-13 09:07:36 +00:00
|
|
|
|
var workflowNumberSource = new WorkflowNumberSource(numberSource.GetNextNumber(),
|
|
|
|
|
containerNumberSource);
|
2023-04-12 13:11:36 +00:00
|
|
|
|
|
2023-10-31 13:48:16 +00:00
|
|
|
|
return new StartupWorkflow(log, workflowNumberSource, cluster, GetNamespace(namespaceOverride));
|
2023-09-13 12:37:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|