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

[#2383] Change k8s lease expiration calculation #2474

Conversation

Arkatufus
Copy link
Contributor

@Arkatufus Arkatufus commented Apr 12, 2024

Fixes #2383

Changes

Change Akka.Coordination.KubernetesApi lease timeout/expiration calculation from DateTime.TimeOfDay.TotalMilliseconds to DateTime.Ticks.

Notes

The wire format is untouched, but the content and its context does. LeaseSpec.Time now represents the absolute DateTime ticks when a lease will expire, instead of the time offset (in milliseconds) when the lease will expire.

Warning

This is not backward compatible with any version below 1.5.18, a CVE will need to be issued to warn users about this breaking change.

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

@Arkatufus Arkatufus marked this pull request as ready for review April 17, 2024 14:28
Copy link
Contributor Author

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self review

@@ -41,7 +41,7 @@ public LeaseResource(string? owner, string version, long time)

public string? Owner { get; }
public string Version { get; }
public long Time { get; }
public DateTime Time { get; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The internal lease resource timeout property now stores the absolute expiration date and time, not the milliseconds offset until lease expiration

_settings.TimeoutSettings.HeartbeatTimeout.TotalMilliseconds -
2 * _settings.TimeoutSettings.HeartbeatInterval.TotalMilliseconds;
private bool HasLeaseTimedOut(DateTime leaseTime)
=> DateTime.UtcNow > leaseTime + _heartbeatTimeout - _heartbeatOffset;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lease timeout calculation is now based on absolute date and time

@@ -384,7 +384,7 @@ private LeaseResource ToLeaseResource(object obj)
return new LeaseResource(
string.IsNullOrWhiteSpace(lease.Spec.Owner) ? null : lease.Spec.Owner,
lease.Metadata.ResourceVersion,
lease.Spec.Time);
DateTime.SpecifyKind(new DateTime(lease.Spec.Time), DateTimeKind.Utc));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converts the stored ticks to DateTime and set the Kind to UTC

@@ -39,7 +39,7 @@ public LeaseSpec()
public LeaseSpec(string? owner, DateTime time)
{
Owner = owner;
Time = (long) time.TimeOfDay.TotalMilliseconds;
Time = time.Ticks;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stores the timeout value to absolute date and time expiration value instead of the millisecond offset until expiration

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb Aaronontheweb merged commit a470da9 into akkadotnet:dev Apr 17, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calculation of lease timeout uses TimeOfDay (Lease can't be aquired the next day!)
2 participants