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; } } }