From 86a8314301486b6f300bf3ad1a51aafe464f2a6a Mon Sep 17 00:00:00 2001 From: Guillaume Gnaegi <58469901+ggnaegi@users.noreply.github.com> Date: Tue, 27 Jun 2023 20:49:28 +0200 Subject: [PATCH] Also refactoring the kubernetes provider factory (like consul and eureka) --- .../KubernetesProviderFactory.cs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs b/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs index 0cfc2a23e5..709c8c2eb5 100644 --- a/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs +++ b/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs @@ -12,30 +12,28 @@ namespace Ocelot.Provider.Kubernetes { public static class KubernetesProviderFactory { - public static ServiceDiscoveryFinderDelegate Get = (provider, config, route) => - { - var factory = provider.GetService(); - 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(); var kubeClient = provider.GetService(); - 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; } } }