private static void AddKubernetesServices(IServiceCollection services) { services.AddKubernetesClient(); services.PostConfigure <KubernetesDiscoveryOptions>(options => { var appOptions = services.GetKubernetesApplicationOptions() as KubernetesApplicationOptions; options.ServiceName = appOptions.ApplicationNameInContext(SteeltoeComponent.Kubernetes, appOptions.KubernetesRoot + ":discovery:servicename"); if (options.Namespace == "default" && appOptions.NameSpace != "default") { options.Namespace = appOptions.NameSpace; } }); services.AddSingleton((p) => { var kubernetesOptions = p.GetRequiredService <IOptions <KubernetesDiscoveryOptions> >(); var kubernetes = p.GetRequiredService <IKubernetes>(); return(KubernetesDiscoveryClientFactory.CreateClient(kubernetesOptions.Value, kubernetes)); }); services.TryAddSingleton(serviceProvider => { var clientOptions = serviceProvider.GetRequiredService <IOptions <KubernetesDiscoveryOptions> >(); return(new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(clientOptions.Value.CacheTTL) }); }); }
private static void ConfigureKubernetesServices(IServiceCollection services) { services.AddKubernetesClient(); services .AddOptions <KubernetesDiscoveryOptions>() .Configure <IConfiguration>((options, config) => config.GetSection(KubernetesDiscoveryOptions.KUBERNETES_DISCOVERY_CONFIGURATION_PREFIX).Bind(options)) .PostConfigure <KubernetesApplicationOptions>((options, appOptions) => { options.ServiceName = appOptions.ApplicationNameInContext(SteeltoeComponent.Kubernetes, appOptions.KubernetesRoot + ":discovery:servicename"); if (options.Namespace == "default" && appOptions.NameSpace != "default") { options.Namespace = appOptions.NameSpace; } }); services.AddSingleton((p) => { var kubernetesOptions = p.GetRequiredService <IOptionsMonitor <KubernetesDiscoveryOptions> >(); var kubernetes = p.GetRequiredService <IKubernetes>(); return(KubernetesDiscoveryClientFactory.CreateClient(kubernetesOptions, kubernetes)); }); services.TryAddSingleton(serviceProvider => { var clientOptions = serviceProvider.GetRequiredService <IOptions <KubernetesDiscoveryOptions> >(); return(new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(clientOptions.Value.CacheTTL) }); }); }
internal static void ConfigureKubernetesServices(IServiceCollection services) { services.AddKubernetesClient(); services .AddOptions <KubernetesDiscoveryOptions>() .Configure <IConfiguration>((options, config) => { config.GetSection(KubernetesDiscoveryOptions.KUBERNETES_DISCOVERY_CONFIGURATION_PREFIX).Bind(options); // Kubernetes discovery is enabled by default. If spring:cloud:kubernetes:discovery:enabled was not set then check spring:cloud:discovery:enabled if (options.Enabled && config.GetValue <bool?>(KubernetesDiscoveryOptions.KUBERNETES_DISCOVERY_CONFIGURATION_PREFIX + ":enabled") is null && config.GetValue <bool?>(_springDiscoveryEnabled) == false) { options.Enabled = false; } }) .PostConfigure <KubernetesApplicationOptions>((options, appOptions) => { options.ServiceName = appOptions.ApplicationNameInContext(SteeltoeComponent.Kubernetes, appOptions.KubernetesRoot + ":discovery:servicename"); if (options.Namespace == "default" && appOptions.NameSpace != "default") { options.Namespace = appOptions.NameSpace; } }); services.AddSingleton((p) => { var kubernetesOptions = p.GetRequiredService <IOptionsMonitor <KubernetesDiscoveryOptions> >(); var kubernetes = p.GetRequiredService <IKubernetes>(); return(KubernetesDiscoveryClientFactory.CreateClient(kubernetesOptions, kubernetes)); }); services.TryAddSingleton(serviceProvider => { var clientOptions = serviceProvider.GetRequiredService <IOptions <KubernetesDiscoveryOptions> >(); return(new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(clientOptions.Value.CacheTTL) }); }); }