Skip to content

Commit

Permalink
Also refactoring the kubernetes provider factory (like consul and eur…
Browse files Browse the repository at this point in the history
…eka)
  • Loading branch information
ggnaegi committed Jun 27, 2023
1 parent 1872228 commit 86a8314
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,28 @@ namespace Ocelot.Provider.Kubernetes
{
public static class KubernetesProviderFactory
{
public static ServiceDiscoveryFinderDelegate Get = (provider, config, route) =>
{
var factory = provider.GetService<IOcelotLoggerFactory>();
return GetKubeProvider(provider, config, route, factory);
};
public static ServiceDiscoveryFinderDelegate Get { get; } = CreateProvider;
private const string PollKube = "pollkube";

private static ServiceDiscovery.Providers.IServiceDiscoveryProvider GetKubeProvider(IServiceProvider provider, ServiceProviderConfiguration config, DownstreamRoute route, IOcelotLoggerFactory factory)
private static ServiceDiscovery.Providers.IServiceDiscoveryProvider CreateProvider(IServiceProvider provider, ServiceProviderConfiguration config, DownstreamRoute route)
{
var factory = provider.GetService<IOcelotLoggerFactory>();
var kubeClient = provider.GetService<IKubeApiClient>();

var k8sRegistryConfiguration = new KubeRegistryConfiguration
var k8SRegistryConfiguration = new KubeRegistryConfiguration
{
KeyOfServiceInK8s = route.ServiceName,
KubeNamespace = string.IsNullOrEmpty(route.ServiceNamespace) ? config.Namespace : route.ServiceNamespace,
};

var k8sServiceDiscoveryProvider = new KubernetesServiceDiscoveryProvider(k8sRegistryConfiguration, factory, kubeClient);
var k8SServiceDiscoveryProvider = new KubernetesServiceDiscoveryProvider(k8SRegistryConfiguration, factory, kubeClient);

if (config.Type?.ToLower() == "pollkube")
if (config.Type?.ToLower() == PollKube)
{
return new PollKubernetes(config.PollingInterval, factory, k8sServiceDiscoveryProvider);
return new PollKubernetes(config.PollingInterval, factory, k8SServiceDiscoveryProvider);
}

return k8sServiceDiscoveryProvider;
return k8SServiceDiscoveryProvider;
}
}
}

0 comments on commit 86a8314

Please sign in to comment.