From 93a1996f1986c2ef2d4989a34e37c55894b432df Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Mon, 18 Mar 2024 23:58:35 +0700 Subject: [PATCH] Update KubernetesClient to 13.0.26 for net6.0 target (#2405) --- src/Directory.Build.props | 3 +- ...ka.Coordination.KubernetesApi.Tests.csproj | 2 +- .../KubernetesApiSpec.cs | 198 +++++++++++------- .../Akka.Coordination.KubernetesApi.csproj | 11 +- .../Internal/KubernetesApiImpl.cs | 74 ++++++- .../Akka.Discovery.KubernetesApi.Tests.csproj | 2 +- .../KubernetesApiServiceDiscoverySpec.cs | 13 +- .../Akka.Discovery.KubernetesApi.csproj | 11 +- .../KubernetesApiServiceDiscovery.cs | 17 +- 9 files changed, 242 insertions(+), 89 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 961bf2ae1..5ab3ecc18 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -35,7 +35,8 @@ Update all AWSSDK versions 1.5.17.1 1.4.0 - 4.0.26 + 4.0.26 + 13.0.26 [6.0.*,) 1.10.4 3.25.3 diff --git a/src/coordination/kubernetes/Akka.Coordination.KubernetesApi.Tests/Akka.Coordination.KubernetesApi.Tests.csproj b/src/coordination/kubernetes/Akka.Coordination.KubernetesApi.Tests/Akka.Coordination.KubernetesApi.Tests.csproj index 96e3e5efc..407b40bfe 100644 --- a/src/coordination/kubernetes/Akka.Coordination.KubernetesApi.Tests/Akka.Coordination.KubernetesApi.Tests.csproj +++ b/src/coordination/kubernetes/Akka.Coordination.KubernetesApi.Tests/Akka.Coordination.KubernetesApi.Tests.csproj @@ -1,7 +1,7 @@ - $(TestsNet) + $(TestsNetCoreFramework);$(TestsNet) false diff --git a/src/coordination/kubernetes/Akka.Coordination.KubernetesApi.Tests/KubernetesApiSpec.cs b/src/coordination/kubernetes/Akka.Coordination.KubernetesApi.Tests/KubernetesApiSpec.cs index 0678993ac..428268688 100644 --- a/src/coordination/kubernetes/Akka.Coordination.KubernetesApi.Tests/KubernetesApiSpec.cs +++ b/src/coordination/kubernetes/Akka.Coordination.KubernetesApi.Tests/KubernetesApiSpec.cs @@ -15,7 +15,6 @@ using Akka.Util; using FluentAssertions; using k8s.Models; -using Microsoft.Rest.Serialization; using WireMock; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; @@ -24,6 +23,13 @@ using WireMock.Util; using Xunit; using Xunit.Abstractions; +using static FluentAssertions.FluentActions; + +#if !NET6_0_OR_GREATER +using Microsoft.Rest.Serialization; +#else +using k8s; +#endif #nullable enable namespace Akka.Coordination.KubernetesApi.Tests @@ -84,22 +90,31 @@ public MockKubernetesApi(ActorSystem system, KubernetesSettings settings) : base public async Task AbleToCreateLeaseResource() { const string version = "1234"; + + var resource = new LeaseCustomResource( + metadata: new V1ObjectMeta + { + Name = LeaseName, + NamespaceProperty = "akka-lease-tests", + ResourceVersion = version, + SelfLink = LeaseApiPath, + Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" + }, + spec: new LeaseSpec(owner: "", time: 1549439255948)); + +#if !NET6_0_OR_GREATER + var json = SafeJsonConvert.SerializeObject(resource); +#else + var json = KubernetesJson.Serialize(resource); +#endif + try { _wireMockServer.Given(Request.Create().UsingPost().WithPath(ApiPath)) .RespondWith(Response.Create() .WithStatusCode(201) .WithHeader("Content-Type", "application/json") - .WithBodyAsJson(new LeaseCustomResource( - new V1ObjectMeta - { - Name = LeaseName, - NamespaceProperty = "akka-lease-tests", - ResourceVersion = version, - SelfLink = LeaseApiPath, - Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" - }, - new LeaseSpec(owner: "", time: 1549439255948)))); + .WithBodyAsJson(json)); (await _underTest.RemoveLease(LeaseName)).Should().Be(Done.Instance); var leaseRecord = await _underTest.ReadOrCreateLeaseResource(LeaseName); @@ -128,7 +143,11 @@ public async Task AbleToUpdateLease() .WithHeader("Content-Type", "application/json") .WithCallback(request => { +#if !NET6_0_OR_GREATER var body = SafeJsonConvert.DeserializeObject(request.Body); +#else + var body = KubernetesJson.Deserialize(request.Body); +#endif var response = new LeaseCustomResource( new V1ObjectMeta { @@ -139,6 +158,11 @@ public async Task AbleToUpdateLease() Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" }, new LeaseSpec(owner: body.Spec.Owner, time: body.Spec.Time)); +#if !NET6_0_OR_GREATER + var responseJson = SafeJsonConvert.SerializeObject(response); +#else + var responseJson = KubernetesJson.Serialize(response); +#endif return new ResponseMessage { BodyDestination = null, @@ -146,7 +170,7 @@ public async Task AbleToUpdateLease() { Encoding = null, DetectedBodyType = BodyType.Json, - BodyAsJson = response, + BodyAsJson = responseJson, BodyAsJsonIndented = false } }; @@ -171,7 +195,25 @@ public async Task ShouldUpdateLeaseConflict() const string conflictOwner = "client2"; const string version = "2"; const string updatedVersion = "3"; + var timestamp = DateTime.UtcNow; + var resource = new LeaseCustomResource( + metadata: new V1ObjectMeta + { + Name = LeaseName, + NamespaceProperty = "akka-lease-tests", + ResourceVersion = updatedVersion, + SelfLink = LeaseApiPath, + Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" + }, + spec: new LeaseSpec(owner: conflictOwner, time: timestamp)); + +#if !NET6_0_OR_GREATER + var json = SafeJsonConvert.SerializeObject(resource); +#else + var json = KubernetesJson.Serialize(resource); +#endif + try { // Conflict @@ -183,15 +225,7 @@ public async Task ShouldUpdateLeaseConflict() .RespondWith(Response.Create() .WithStatusCode(HttpStatusCode.OK) .WithHeader("Content-Type", "application/json") - .WithBodyAsJson(new LeaseCustomResource( - new V1ObjectMeta - { - Name = LeaseName, - NamespaceProperty = "akka-lease-tests", - ResourceVersion = updatedVersion, - SelfLink = LeaseApiPath, - Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" - }, new LeaseSpec(owner: conflictOwner, time: timestamp)))); + .WithBodyAsJson(json)); var response = await _underTest.UpdateLeaseResource(LeaseName, owner, version, timestamp); response.Should().BeOfType>(); @@ -213,7 +247,9 @@ public async Task ShouldRemoveLease() try { _wireMockServer.Given(Request.Create().UsingDelete().WithPath(LeaseApiPath)) - .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + .RespondWith(Response.Create() + .WithBodyAsJson(new object()) + .WithStatusCode(HttpStatusCode.OK)); var response = await _underTest.RemoveLease(LeaseName); response.Should().Be(Done.Instance); @@ -229,7 +265,24 @@ public async Task ShouldTimeOutOnRead() { const string owner = "client1"; const string version = "2"; + var timestamp = DateTime.UtcNow; + var resource = new LeaseCustomResource( + metadata: new V1ObjectMeta + { + Name = LeaseName, + NamespaceProperty = "akka-lease-tests", + ResourceVersion = version, + SelfLink = LeaseApiPath, + Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" + }, + spec: new LeaseSpec(owner: owner, time: timestamp)); + +#if !NET6_0_OR_GREATER + var json = SafeJsonConvert.SerializeObject(resource); +#else + var json = KubernetesJson.Serialize(resource); +#endif try { @@ -238,21 +291,10 @@ public async Task ShouldTimeOutOnRead() .WithDelay((int)(_settings.ApiServiceRequestTimeout.TotalMilliseconds * 2)) // time out .WithStatusCode(HttpStatusCode.OK) .WithHeader("Content-Type", "application/json") - .WithBodyAsJson(new LeaseCustomResource( - new V1ObjectMeta - { - Name = LeaseName, - NamespaceProperty = "akka-lease-tests", - ResourceVersion = version, - SelfLink = LeaseApiPath, - Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" - }, new LeaseSpec(owner: owner, time: timestamp)))); - var exception = await Record.ExceptionAsync( async () => - { - await _underTest.ReadOrCreateLeaseResource(LeaseName); - }); - exception.Should().BeOfType(); - exception.Message.Should().StartWith($"Timed out reading lease {LeaseName}."); + .WithBodyAsJson(json)); + await Awaiting(() => _underTest.ReadOrCreateLeaseResource(LeaseName)).Should() + .ThrowAsync() + .WithMessage($"Timed out reading lease {LeaseName}.*"); } finally { @@ -266,6 +308,22 @@ public async Task ShouldTimeOutOnCreate() const string owner = "client1"; const string version = "2"; var timestamp = DateTime.UtcNow; + var resource = new LeaseCustomResource( + metadata: new V1ObjectMeta + { + Name = LeaseName, + NamespaceProperty = "akka-lease-tests", + ResourceVersion = version, + SelfLink = LeaseApiPath, + Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" + }, + spec: new LeaseSpec(owner: owner, time: timestamp)); + +#if !NET6_0_OR_GREATER + var json = SafeJsonConvert.SerializeObject(resource); +#else + var json = KubernetesJson.Serialize(resource); +#endif try { @@ -277,21 +335,10 @@ public async Task ShouldTimeOutOnCreate() .WithDelay((int)(_settings.ApiServiceRequestTimeout.TotalMilliseconds * 2)) // time out .WithStatusCode(HttpStatusCode.OK) .WithHeader("Content-Type", "application/json") - .WithBodyAsJson(new LeaseCustomResource( - new V1ObjectMeta - { - Name = LeaseName, - NamespaceProperty = "akka-lease-tests", - ResourceVersion = version, - SelfLink = LeaseApiPath, - Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" - }, new LeaseSpec(owner: owner, time: timestamp)))); - var exception = await Record.ExceptionAsync( async () => - { - await _underTest.ReadOrCreateLeaseResource(LeaseName); - }); - exception.Should().BeOfType(); - exception.Message.Should().StartWith($"Timed out creating lease {LeaseName}."); + .WithBodyAsJson(json)); + await Awaiting(() => _underTest.ReadOrCreateLeaseResource(LeaseName)).Should() + .ThrowAsync() + .WithMessage($"Timed out creating lease {LeaseName}.*"); } finally { @@ -304,8 +351,25 @@ public async Task ShouldTimeOutOnUpdate() { const string owner = "client1"; const string version = "2"; + var timestamp = DateTime.UtcNow; + var resource = new LeaseCustomResource( + metadata: new V1ObjectMeta + { + Name = LeaseName, + NamespaceProperty = "akka-lease-tests", + ResourceVersion = version, + SelfLink = LeaseApiPath, + Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" + }, + spec: new LeaseSpec(owner: owner, time: timestamp)); +#if !NET6_0_OR_GREATER + var json = SafeJsonConvert.SerializeObject(resource); +#else + var json = KubernetesJson.Serialize(resource); +#endif + try { _wireMockServer.Given(Request.Create().UsingPut().WithPath(LeaseApiPath)) @@ -313,21 +377,10 @@ public async Task ShouldTimeOutOnUpdate() .WithDelay((int)(_settings.ApiServiceRequestTimeout.TotalMilliseconds * 2)) // time out .WithStatusCode(HttpStatusCode.OK) .WithHeader("Content-Type", "application/json") - .WithBodyAsJson(new LeaseCustomResource( - new V1ObjectMeta - { - Name = LeaseName, - NamespaceProperty = "akka-lease-tests", - ResourceVersion = version, - SelfLink = LeaseApiPath, - Uid = "c369949e-296c-11e9-9c62-16f8dd5735ba" - }, new LeaseSpec(owner: owner, time: timestamp)))); - var exception = await Record.ExceptionAsync( async () => - { - await _underTest.UpdateLeaseResource(LeaseName, owner, version); - }); - exception.Should().BeOfType(); - exception.Message.Should().StartWith($"Timed out updating lease {LeaseName} to owner {owner}. It is not known if the update happened."); + .WithBodyAsJson(json)); + await Awaiting(() => _underTest.UpdateLeaseResource(LeaseName, owner, version)).Should() + .ThrowAsync() + .WithMessage($"Timed out updating lease {LeaseName} to owner {owner}. It is not known if the update happened.*"); } finally { @@ -344,13 +397,10 @@ public async Task ShouldTimeOutOnRemove() .RespondWith(Response.Create() .WithDelay((int)(_settings.ApiServiceRequestTimeout.TotalMilliseconds * 2)) // time out .WithStatusCode(HttpStatusCode.OK)); - - var exception = await Record.ExceptionAsync( async () => - { - await _underTest.RemoveLease(LeaseName); - }); - exception.Should().BeOfType(); - exception.Message.Should().StartWith($"Timed out removing lease {LeaseName}. It is not known if the remove happened."); + + await Awaiting(() => _underTest.RemoveLease(LeaseName)).Should() + .ThrowAsync() + .WithMessage($"Timed out removing lease {LeaseName}. It is not known if the remove happened.*"); } finally { diff --git a/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/Akka.Coordination.KubernetesApi.csproj b/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/Akka.Coordination.KubernetesApi.csproj index f58358291..856f3293e 100644 --- a/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/Akka.Coordination.KubernetesApi.csproj +++ b/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/Akka.Coordination.KubernetesApi.csproj @@ -1,7 +1,7 @@ - $(LibraryFramework) + $(LibraryFramework);$(NetFramework) Akka.NET coordination module for Kubernetes $(AkkaPackageTags);Kubernetes; true @@ -12,7 +12,14 @@ - + + + + + + + + diff --git a/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/Internal/KubernetesApiImpl.cs b/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/Internal/KubernetesApiImpl.cs index 2fcc94b32..4debf0d8d 100644 --- a/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/Internal/KubernetesApiImpl.cs +++ b/src/coordination/kubernetes/Akka.Coordination.KubernetesApi/Internal/KubernetesApiImpl.cs @@ -18,9 +18,14 @@ using k8s; using k8s.Authentication; using k8s.Models; +using Newtonsoft.Json; + +#if !NET6_0_OR_GREATER using Microsoft.Rest; using Microsoft.Rest.Serialization; -using Newtonsoft.Json; +#else +using k8s.Autorest; +#endif #nullable enable namespace Akka.Coordination.KubernetesApi.Internal @@ -99,6 +104,7 @@ public async Task ReadOrCreateLeaseResource(string name) metadata: new V1ObjectMeta(name: leaseName, resourceVersion: version), spec: new LeaseSpec(owner: ownerName, time: time ?? DateTime.UtcNow)); _log.Debug("Updating {0} to {1}", leaseName, leaseBody); +#if !NET6_0_OR_GREATER using var operationResponse = await _client .ReplaceNamespacedCustomObjectWithHttpMessagesAsync( body: leaseBody, @@ -109,8 +115,20 @@ public async Task ReadOrCreateLeaseResource(string name) name: leaseName, cancellationToken: cts.Token) .ConfigureAwait(false); - var newLease = operationResponse.Body; +#else + var operationResponse = await _client.ReplaceNamespacedCustomObjectAsync( + body: leaseBody, + @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(ToLeaseResource(newLease)); } @@ -142,11 +160,15 @@ public async Task ReadOrCreateLeaseResource(string name) } catch (OperationCanceledException e) { - throw new LeaseTimeoutException($"Timed out updating lease {leaseName} to owner {ownerName}. It is not known if the update happened. Is the API server up?", e); + throw new LeaseTimeoutException( + $"Timed out updating lease {leaseName} to owner {ownerName}. It is not known if the update happened. Is the API server up?", + e); } catch (TimeoutException e) { - throw new LeaseTimeoutException($"Timed out updating lease {leaseName} to owner {ownerName}. It is not known if the update happened. Is the API server up?", e); + throw new LeaseTimeoutException( + $"Timed out updating lease {leaseName} to owner {ownerName}. It is not known if the update happened. Is the API server up?", + e); } } @@ -158,6 +180,7 @@ public async Task ReadOrCreateLeaseResource(string name) var leaseBody = new LeaseCustomResource( metadata: new V1ObjectMeta(name: name, namespaceProperty: _namespace), spec: new LeaseSpec(owner: "", time: DateTime.UtcNow)); +#if !NET6_0_OR_GREATER using var operationResponse = await _client .CreateNamespacedCustomObjectWithHttpMessagesAsync( leaseBody, @@ -170,6 +193,19 @@ public async Task ReadOrCreateLeaseResource(string name) _log.Debug("Lease resource created"); return ToLeaseResource(operationResponse.Body); +#else + var operationResponse = await _client + .CreateNamespacedCustomObjectAsync( + body: leaseBody, + group: _crd.Group, + version: _crd.Version, + namespaceParameter: _namespace, + plural: _crd.PluralName, + cancellationToken: cts.Token); + + _log.Debug("Lease resource created"); + return ToLeaseResource(operationResponse); +#endif } catch (HttpOperationException e) { @@ -210,6 +246,7 @@ public async Task ReadOrCreateLeaseResource(string name) var cts = new CancellationTokenSource(_settings.BodyReadTimeout); try { +#if !NET6_0_OR_GREATER using var operationResponse = await _client .GetNamespacedCustomObjectWithHttpMessagesAsync( @group: _crd.Group, @@ -223,6 +260,20 @@ public async Task ReadOrCreateLeaseResource(string name) // it exists, parse it _log.Debug("Resource {0} exists: {1}", name, operationResponse.Response); return ToLeaseResource(operationResponse.Body.ToString()); +#else + var operationResponse = await _client + .GetNamespacedCustomObjectAsync( + group: _crd.Group, + version: _crd.Version, + namespaceParameter: _namespace, + plural: _crd.PluralName, + name: name, + cancellationToken: cts.Token); + + // it exists, parse it + _log.Debug("Resource {0} exists: {1}", name, operationResponse); + return ToLeaseResource(operationResponse); +#endif } catch (HttpOperationException e) { @@ -261,6 +312,7 @@ internal async Task RemoveLease(string name) var cts = new CancellationTokenSource(_settings.BodyReadTimeout); try { +#if !NET6_0_OR_GREATER using var operationResponse = await _client .DeleteNamespacedCustomObjectWithHttpMessagesAsync( @group: _crd.Group, @@ -270,6 +322,16 @@ internal async Task RemoveLease(string name) name: name, cancellationToken: cts.Token) .ConfigureAwait(false); +#else + var operationResponse = await _client + .DeleteNamespacedCustomObjectAsync( + group: _crd.Group, + version: _crd.Version, + namespaceParameter: _namespace, + plural: _crd.PluralName, + name: name, + cancellationToken: cts.Token); +#endif _log.Debug("Lease deleted: {0}", name); return Done.Instance; } @@ -307,7 +369,11 @@ internal async Task RemoveLease(string name) private LeaseResource ToLeaseResource(object obj) { +#if !NET6_0_OR_GREATER var lease = SafeJsonConvert.DeserializeObject(obj.ToString()); +#else + var lease = KubernetesJson.Deserialize(obj.ToString()); +#endif _log.Debug("Converting {0}", lease); if (lease.Metadata.ResourceVersion == null) { diff --git a/src/discovery/kubernetes/Akka.Discovery.KubernetesApi.Tests/Akka.Discovery.KubernetesApi.Tests.csproj b/src/discovery/kubernetes/Akka.Discovery.KubernetesApi.Tests/Akka.Discovery.KubernetesApi.Tests.csproj index 4be31bf26..973f3d5e6 100644 --- a/src/discovery/kubernetes/Akka.Discovery.KubernetesApi.Tests/Akka.Discovery.KubernetesApi.Tests.csproj +++ b/src/discovery/kubernetes/Akka.Discovery.KubernetesApi.Tests/Akka.Discovery.KubernetesApi.Tests.csproj @@ -1,7 +1,7 @@ - $(TestsNet) + $(TestsNetCoreFramework);$(TestsNet) false diff --git a/src/discovery/kubernetes/Akka.Discovery.KubernetesApi.Tests/KubernetesApiServiceDiscoverySpec.cs b/src/discovery/kubernetes/Akka.Discovery.KubernetesApi.Tests/KubernetesApiServiceDiscoverySpec.cs index 3561bf874..714639964 100644 --- a/src/discovery/kubernetes/Akka.Discovery.KubernetesApi.Tests/KubernetesApiServiceDiscoverySpec.cs +++ b/src/discovery/kubernetes/Akka.Discovery.KubernetesApi.Tests/KubernetesApiServiceDiscoverySpec.cs @@ -9,15 +9,18 @@ using System.Collections.Generic; using System.IO; using System.Net; -using System.Text.Json; -using System.Text.Json.Serialization; using System.Threading.Tasks; using Akka.Actor; using FluentAssertions; using k8s.Models; -using Microsoft.Rest.Serialization; using Xunit; +#if !NET6_0_OR_GREATER +using Microsoft.Rest.Serialization; +#else +using k8s; +#endif + namespace Akka.Discovery.KubernetesApi.Tests { public class KubernetesApiServiceDiscoverySpec @@ -246,7 +249,11 @@ public void IgnoreNonRunningPods() public void IgnoreRunningPodsWhereContainerIsWaiting() { var json = LoadResource("Akka.Discovery.KubernetesApi.Tests.multi-container-pod.json"); +#if !NET6_0_OR_GREATER var podList = SafeJsonConvert.DeserializeObject(json); +#else + var podList = KubernetesJson.Deserialize(json); +#endif KubernetesApiServiceDiscovery.Targets( podList, diff --git a/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/Akka.Discovery.KubernetesApi.csproj b/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/Akka.Discovery.KubernetesApi.csproj index 6db9e8b6b..d38af56fb 100644 --- a/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/Akka.Discovery.KubernetesApi.csproj +++ b/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/Akka.Discovery.KubernetesApi.csproj @@ -1,7 +1,7 @@ - $(LibraryFramework) + $(LibraryFramework);$(NetFramework) Akka.NET discovery module for Kubernetes $(AkkaPackageTags);Kubernetes; true @@ -11,7 +11,14 @@ - + + + + + + + + diff --git a/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/KubernetesApiServiceDiscovery.cs b/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/KubernetesApiServiceDiscovery.cs index 5a058dbd0..821728be6 100644 --- a/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/KubernetesApiServiceDiscovery.cs +++ b/src/discovery/kubernetes/Akka.Discovery.KubernetesApi/KubernetesApiServiceDiscovery.cs @@ -17,9 +17,16 @@ using k8s; using k8s.Authentication; using k8s.Models; -using Microsoft.Rest; using Newtonsoft.Json; +#if !NET6_0_OR_GREATER +using Microsoft.Rest; +#else +using System.Runtime.Serialization; +using k8s.Autorest; +#endif + + namespace Akka.Discovery.KubernetesApi { public class KubernetesApiServiceDiscovery : ServiceDiscovery @@ -89,12 +96,20 @@ public override async Task Lookup(Lookup lookup, TimeSpan resolveTimeo V1PodList podList; try { +#if !NET6_0_OR_GREATER var result = await _client.ListNamespacedPodWithHttpMessagesAsync( namespaceParameter: PodNamespace, labelSelector: labelSelector, cancellationToken: cts.Token) .ConfigureAwait(false); podList = result.Body; +#else + var result = await _client.ListNamespacedPodAsync( + namespaceParameter: PodNamespace, + labelSelector: labelSelector, + cancellationToken: cts.Token); + podList = result; +#endif } catch (SerializationException e) {