Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Coordination.Kubernetes settings #2475

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ public void HostingExtension1Test()
builder.WithKubernetesLease();

builder.Configuration.HasValue.Should().BeTrue();
var config = builder.Configuration.Value.GetConfig(KubernetesLease.ConfigPath);
config.Should().NotBeNull();
config = config.WithFallback(builder.Configuration.Value.GetConfig("akka.coordination.lease"));
builder.Configuration.Value.GetConfig(KubernetesLease.ConfigPath).Should().NotBeNull();

var settings = KubernetesSettings.Create(config);
var leaseSettings = GetSettings(builder);
var settings = KubernetesSettings.Create(leaseSettings);
settings.ApiCaPath.Should().Be("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt");
settings.ApiTokenPath.Should().Be("/var/run/secrets/kubernetes.io/serviceaccount/token");
settings.ApiServiceHostEnvName.Should().Be("KUBERNETES_SERVICE_HOST");
Expand All @@ -46,7 +45,7 @@ public void HostingExtension1Test()
settings.Secure.Should().BeTrue();
settings.BodyReadTimeout.Should().Be(1.Seconds());

var timeSettings = TimeoutSettings.Create(config);
var timeSettings = TimeoutSettings.Create(leaseSettings.LeaseConfig);
timeSettings.HeartbeatInterval.Should().Be(12.Seconds());
timeSettings.HeartbeatTimeout.Should().Be(120.Seconds());
timeSettings.OperationTimeout.Should().Be(5.Seconds());
Expand All @@ -73,11 +72,10 @@ public void HostingExtension2Test()
});

builder.Configuration.HasValue.Should().BeTrue();
var config = builder.Configuration.Value.GetConfig(KubernetesLease.ConfigPath);
config.Should().NotBeNull();
config = config.WithFallback(builder.Configuration.Value.GetConfig("akka.coordination.lease"));
builder.Configuration.Value.GetConfig(KubernetesLease.ConfigPath).Should().NotBeNull();

var settings = KubernetesSettings.Create(config);
var leaseSettings = GetSettings(builder);
var settings = KubernetesSettings.Create(leaseSettings);
settings.ApiCaPath.Should().Be("a");
settings.ApiTokenPath.Should().Be("b");
settings.ApiServiceHostEnvName.Should().Be("c");
Expand All @@ -88,7 +86,7 @@ public void HostingExtension2Test()
settings.Secure.Should().BeFalse();
settings.BodyReadTimeout.Should().Be(1.5.Seconds());

var timeSettings = TimeoutSettings.Create(config);
var timeSettings = TimeoutSettings.Create(leaseSettings.LeaseConfig);
timeSettings.HeartbeatInterval.Should().Be(4.Seconds());
timeSettings.HeartbeatTimeout.Should().Be(10.Seconds());
timeSettings.OperationTimeout.Should().Be(4.Seconds());
Expand All @@ -115,9 +113,10 @@ public void HostingExtension3Test()
});

builder.Configuration.HasValue.Should().BeTrue();
var config = builder.Configuration.Value.GetConfig(KubernetesLease.ConfigPath);
config.Should().NotBeNull();
var settings = KubernetesSettings.Create(config);
builder.Configuration.Value.GetConfig(KubernetesLease.ConfigPath).Should().NotBeNull();

var leaseSettings = GetSettings(builder);
var settings = KubernetesSettings.Create(leaseSettings);
settings.ApiCaPath.Should().Be("a");
settings.ApiTokenPath.Should().Be("b");
settings.ApiServiceHostEnvName.Should().Be("c");
Expand All @@ -128,10 +127,21 @@ public void HostingExtension3Test()
settings.Secure.Should().BeFalse();
settings.BodyReadTimeout.Should().Be(1.5.Seconds());

var timeSettings = TimeoutSettings.Create(config);
var timeSettings = TimeoutSettings.Create(leaseSettings.LeaseConfig);
timeSettings.HeartbeatInterval.Should().Be(4.Seconds());
timeSettings.HeartbeatTimeout.Should().Be(10.Seconds());
timeSettings.OperationTimeout.Should().Be(4.Seconds());
}

private static LeaseSettings GetSettings(AkkaConfigurationBuilder builder)
{
// NOTE: this is how LeaseSettings is created in Akka.Coordination
// https://github.com/akkadotnet/akka.net/blob/f75886921174746cf80244ec18c4e61923725a2d/src/core/Akka.Coordination/LeaseProvider.cs#L127-L131
var leaseConfig = builder.Configuration.Value
.GetConfig(KubernetesLease.ConfigPath)
.WithFallback(builder.Configuration.Value.GetConfig("akka.coordination.lease"));

return LeaseSettings.Create(leaseConfig, "lease-name", "owner-name");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ private static KubernetesSettings Conf(string? overrides)
.WithFallback(LeaseProvider.DefaultConfig())
: KubernetesLease.DefaultConfiguration
.WithFallback(LeaseProvider.DefaultConfig());
return KubernetesSettings.Create(config.GetConfig(KubernetesLease.ConfigPath).WithFallback(config.GetConfig("akka.coordination.lease")));

// NOTE: this is how LeaseSettings is created in Akka.Coordination
// https://github.com/akkadotnet/akka.net/blob/f75886921174746cf80244ec18c4e61923725a2d/src/core/Akka.Coordination/LeaseProvider.cs#L127-L131
var leaseConfig = config
.GetConfig(KubernetesLease.ConfigPath)
.WithFallback(config.GetConfig("akka.coordination.lease"));

var leaseSettings = LeaseSettings.Create(leaseConfig, "lease-name", "owner-name");
return KubernetesSettings.Create(leaseSettings);
}

[Fact(DisplayName = "default request-timeout should be 2/5 of the lease-operation-timeout")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public KubernetesLease(ExtendedActorSystem system, AtomicBoolean leaseTaken, Lea
_settings = settings;

_log = Logging.GetLogger(system, GetType());
var kubernetesSettings = KubernetesSettings.Create(system);
var kubernetesSettings = KubernetesSettings.Create(settings);

var setup = system.Settings.Setup.Get<KubernetesLeaseSetup>();
if (setup.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ public KubernetesSettings(
BodyReadTimeout = bodyReadTimeout ?? TimeSpan.FromSeconds(1);
}

public static KubernetesSettings Create(ActorSystem system)
=> Create(system.Settings.Config.GetConfig(KubernetesLease.ConfigPath));

public static KubernetesSettings Create(Config config)
public static KubernetesSettings Create(LeaseSettings settings)
{
var leaseTimeoutSettings = TimeoutSettings.Create(config);
var config = settings.LeaseConfig;
var leaseTimeoutSettings = settings.TimeoutSettings;
var requestTimeoutValue = config.GetStringIfDefined("api-service-request-timeout");
var apiServerRequestTimeout = !string.IsNullOrWhiteSpace(requestTimeoutValue)
? config.GetTimeSpan("api-service-request-timeout")
Expand Down