mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-12-30 04:05:48 +08:00
* Allow default k8s namespace to be overridden * Add ServiceNamespace to ReRoute configuration * Remove debug comments * Update unit tests * Unit tests (Eureka) * Update docs * Re-run build
36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using KubeClient;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Ocelot.Logging;
|
|
using Ocelot.ServiceDiscovery;
|
|
using System;
|
|
using Ocelot.Configuration;
|
|
|
|
namespace Ocelot.Provider.Kubernetes
|
|
{
|
|
public static class KubernetesProviderFactory
|
|
{
|
|
public static ServiceDiscoveryFinderDelegate Get = (provider, config, reRoute) =>
|
|
{
|
|
var factory = provider.GetService<IOcelotLoggerFactory>();
|
|
return GetkubeProvider(provider, config, reRoute, factory);
|
|
};
|
|
|
|
private static ServiceDiscovery.Providers.IServiceDiscoveryProvider GetkubeProvider(IServiceProvider provider, Configuration.ServiceProviderConfiguration config, DownstreamReRoute reRoute, IOcelotLoggerFactory factory)
|
|
{
|
|
var kubeClient = provider.GetService<IKubeApiClient>();
|
|
var k8sRegistryConfiguration = new KubeRegistryConfiguration()
|
|
{
|
|
KeyOfServiceInK8s = reRoute.ServiceName,
|
|
KubeNamespace = string.IsNullOrEmpty(reRoute.ServiceNamespace) ? config.Namespace : reRoute.ServiceNamespace
|
|
};
|
|
|
|
var k8sServiceDiscoveryProvider = new Kube(k8sRegistryConfiguration, factory, kubeClient);
|
|
if (config.Type?.ToLower() == "pollkube")
|
|
{
|
|
return new PollKube(config.PollingInterval, factory, k8sServiceDiscoveryProvider);
|
|
}
|
|
return k8sServiceDiscoveryProvider;
|
|
}
|
|
}
|
|
}
|