forked from dotnet/orleans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kubernetes hosting integration (dotnet#6707)
* Add IClusterMembershipService.TryKill method for unilaterally declaring a silo dead * Add Orleans.Hosting.Kubernetes extension * Use PostConfigure for configuring EndpointOptions * Extras * Scope pod labels * Mark Orleans.Hosting.Kubernetes package as beta Co-authored-by: Benjamin Petit <[email protected]>
- Loading branch information
1 parent
05c4c4b
commit 147b214
Showing
16 changed files
with
766 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/Orleans.Hosting.Kubernetes/ConfigureKubernetesHostingOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using AutoMapper.Configuration.Annotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Orleans.Configuration; | ||
using System; | ||
using System.Net; | ||
|
||
namespace Orleans.Hosting.Kubernetes | ||
{ | ||
internal class ConfigureKubernetesHostingOptions : | ||
IConfigureOptions<ClusterOptions>, | ||
IConfigureOptions<SiloOptions>, | ||
IPostConfigureOptions<EndpointOptions>, | ||
IConfigureOptions<KubernetesHostingOptions> | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public ConfigureKubernetesHostingOptions(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public void Configure(KubernetesHostingOptions options) | ||
{ | ||
options.Namespace = Environment.GetEnvironmentVariable(KubernetesHostingOptions.PodNamespaceEnvironmentVariable); | ||
options.PodName = Environment.GetEnvironmentVariable(KubernetesHostingOptions.PodNameEnvironmentVariable); | ||
options.PodIP = Environment.GetEnvironmentVariable(KubernetesHostingOptions.PodIPEnvironmentVariable); | ||
} | ||
|
||
public void Configure(ClusterOptions options) | ||
{ | ||
options.ServiceId = Environment.GetEnvironmentVariable(KubernetesHostingOptions.ServiceIdEnvironmentVariable); | ||
options.ClusterId = Environment.GetEnvironmentVariable(KubernetesHostingOptions.ClusterIdEnvironmentVariable); | ||
} | ||
|
||
public void Configure(SiloOptions options) | ||
{ | ||
options.SiloName = Environment.GetEnvironmentVariable(KubernetesHostingOptions.PodNameEnvironmentVariable); | ||
} | ||
|
||
public void PostConfigure(string name, EndpointOptions options) | ||
{ | ||
// Use PostConfigure to give the developer an opportunity to set SiloPort and GatewayPort using regular | ||
// Configure methods without needing to worry about ordering with respect to the UseKubernetesHosting call. | ||
if (options.AdvertisedIPAddress is null) | ||
{ | ||
var hostingOptions = _serviceProvider.GetRequiredService<IOptions<KubernetesHostingOptions>>().Value; | ||
var podIp = IPAddress.Parse(hostingOptions.PodIP); | ||
options.AdvertisedIPAddress = podIp; | ||
} | ||
|
||
if (options.SiloListeningEndpoint is null) | ||
{ | ||
options.SiloListeningEndpoint = new IPEndPoint(IPAddress.Any, options.SiloPort); | ||
} | ||
|
||
if (options.GatewayListeningEndpoint is null && options.GatewayPort > 0) | ||
{ | ||
options.GatewayListeningEndpoint = new IPEndPoint(IPAddress.Any, options.GatewayPort); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.