-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
KubeServiceBuilder.cs
36 lines (28 loc) · 1.3 KB
/
KubeServiceBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using KubeClient.Models;
using Ocelot.Logging;
using Ocelot.Provider.Kubernetes.Interfaces;
using Ocelot.Values;
namespace Ocelot.Provider.Kubernetes;
public class KubeServiceBuilder : IKubeServiceBuilder
{
private readonly IOcelotLogger _logger;
private readonly IKubeServiceCreator _serviceCreator;
public KubeServiceBuilder(IOcelotLoggerFactory factory, IKubeServiceCreator serviceCreator)
{
ArgumentNullException.ThrowIfNull(factory);
_logger = factory.CreateLogger<KubeServiceBuilder>();
ArgumentNullException.ThrowIfNull(serviceCreator);
_serviceCreator = serviceCreator;
}
public virtual IEnumerable<Service> BuildServices(KubeRegistryConfiguration configuration, EndpointsV1 endpoint)
{
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(endpoint);
var services = endpoint.Subsets
.SelectMany(subset => _serviceCreator.Create(configuration, endpoint, subset))
.ToArray();
_logger.LogDebug(() => $"K8s '{Check(endpoint.Kind)}:{Check(endpoint.ApiVersion)}:{Check(endpoint.Metadata?.Name)}' endpoint: Total built {services.Length} services.");
return services;
}
private static string Check(string str) => string.IsNullOrEmpty(str) ? "?" : str;
}