-
Notifications
You must be signed in to change notification settings - Fork 11
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
[#2383] Change k8s lease expiration calculation #2474
Conversation
There was a problem hiding this 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; } |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #2383
Changes
Change Akka.Coordination.KubernetesApi lease timeout/expiration calculation from
DateTime.TimeOfDay.TotalMilliseconds
toDateTime.Ticks
.Notes
The wire format is untouched, but the content and its context does.
LeaseSpec.Time
now represents the absoluteDateTime
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):