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 Kubernetes LeaseActor and improve logging #2891

Merged
merged 1 commit into from
Nov 8, 2024
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 @@ -97,7 +97,7 @@ public async Task<LeaseResource> ReadOrCreateLeaseResource(string name)
public async Task<Either<LeaseResource, LeaseResource>> UpdateLeaseResource(
string leaseName, string ownerName, string version, DateTime? time = null)
{
var cts = new CancellationTokenSource(_settings.BodyReadTimeout);
using var cts = new CancellationTokenSource(_settings.BodyReadTimeout);
try
{
var leaseBody = new LeaseCustomResource(
Expand All @@ -117,20 +117,20 @@ public async Task<Either<LeaseResource, LeaseResource>> UpdateLeaseResource(
.ConfigureAwait(false);
var newLease = operationResponse.Body;
#else
var operationResponse = await _client.ReplaceNamespacedCustomObjectAsync(
var newLease = await _client.ReplaceNamespacedCustomObjectAsync(
body: leaseBody,
@group: _crd.Group,
group: _crd.Group,
version: _crd.Version,
namespaceParameter: _namespace,
plural: _crd.PluralName,
name: leaseName,
cancellationToken: cts.Token
);
var newLease = operationResponse;
#endif

_log.Debug("Lease after update: {0}", JsonConvert.SerializeObject(newLease));
return new Right<LeaseResource, LeaseResource>(ToLeaseResource(newLease));
var lease = ToLeaseResource(newLease);
_log.Debug("Lease after update: {0}", lease);
return new Right<LeaseResource, LeaseResource>(lease);
}
catch (HttpOperationException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public LeaseResource(string? owner, string version, DateTime time)
public DateTime Time { get; }

public bool IsTaken => Owner != null;

public override string ToString()
=> $"{{owner:{Owner}, version:{Version}, time:{Time}}}";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public KubernetesLease(ExtendedActorSystem system, AtomicBoolean leaseTaken, Lea
var client = new KubernetesApiImpl(system, kubernetesSettings);
_timeout = _settings.TimeoutSettings.OperationTimeout;
_leaseName = MakeDns1039Compatible(settings.LeaseName);
_leaseActor = system.ActorOf(
_leaseActor = system.SystemActorOf(
Aaronontheweb marked this conversation as resolved.
Show resolved Hide resolved
LeaseActor.Props(client, settings, _leaseName, leaseTaken),
$"KubernetesLease{LeaseCounter.GetAndIncrement()}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public LeaseActor(IKubernetesApi client, LeaseSettings settings, string leaseNam
if (!(@event.FsmEvent is WriteResponse writeResponse))
return null;

// FIXME deal with failure from releasing the the lock, currently handled in whenUnhandled but could retry to remove: https://github.com/lightbend/akka-commercial-addons/issues/502
// FIXME deal with failure from releasing the lock, currently handled in whenUnhandled but could retry to remove: https://github.com/lightbend/akka-commercial-addons/issues/502
var response = writeResponse.Response;
var data = (OperationInProgress) @event.StateData;
var who = data.ReplyTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public LeaseCustomResource(
Kind = "Lease";
ApiVersion = "akka.io/v1";
}

public override string ToString()
=> $"{{owner:{Spec.Owner}, version:{Metadata.ResourceVersion}, time:{Spec.Time}}}";
}

internal sealed class LeaseSpec
Expand Down