Skip to content

Commit

Permalink
Update KubernetesClient to 13.0.26 for net6.0 target (#2405)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus committed Mar 18, 2024
1 parent 6d13edb commit 93a1996
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 89 deletions.
3 changes: 2 additions & 1 deletion src/Directory.Build.props
Expand Up @@ -35,7 +35,8 @@ Update all AWSSDK versions</PackageReleaseNotes>
<AkkaHostingVersion>1.5.17.1</AkkaHostingVersion>
<PbmVersion>1.4.0</PbmVersion>

<KubernetesClientVersion>4.0.26</KubernetesClientVersion>
<KubernetesClientVersionNetStandard>4.0.26</KubernetesClientVersionNetStandard>
<KubernetesClientVersionNet>13.0.26</KubernetesClientVersionNet>
<MicrosoftExtensionsVersion>[6.0.*,)</MicrosoftExtensionsVersion>
<AzureIdentityVersion>1.10.4</AzureIdentityVersion>
<ProtobufVersion>3.25.3</ProtobufVersion>
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TestsNet)</TargetFramework>
<TargetFrameworks>$(TestsNetCoreFramework);$(TestsNet)</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Expand Up @@ -15,7 +15,6 @@
using Akka.Util;
using FluentAssertions;
using k8s.Models;
using Microsoft.Rest.Serialization;
using WireMock;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -128,7 +143,11 @@ public async Task AbleToUpdateLease()
.WithHeader("Content-Type", "application/json")
.WithCallback(request =>
{
#if !NET6_0_OR_GREATER
var body = SafeJsonConvert.DeserializeObject<LeaseCustomResource>(request.Body);
#else
var body = KubernetesJson.Deserialize<LeaseCustomResource>(request.Body);
#endif
var response = new LeaseCustomResource(
new V1ObjectMeta
{
Expand All @@ -139,14 +158,19 @@ 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,
BodyData = new BodyData
{
Encoding = null,
DetectedBodyType = BodyType.Json,
BodyAsJson = response,
BodyAsJson = responseJson,
BodyAsJsonIndented = false
}
};
Expand All @@ -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
Expand All @@ -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<Left<LeaseResource, LeaseResource>>();
Expand All @@ -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);
Expand All @@ -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
{
Expand All @@ -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<LeaseTimeoutException>();
exception.Message.Should().StartWith($"Timed out reading lease {LeaseName}.");
.WithBodyAsJson(json));
await Awaiting(() => _underTest.ReadOrCreateLeaseResource(LeaseName)).Should()
.ThrowAsync<LeaseTimeoutException>()
.WithMessage($"Timed out reading lease {LeaseName}.*");
}
finally
{
Expand All @@ -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
{
Expand All @@ -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<LeaseTimeoutException>();
exception.Message.Should().StartWith($"Timed out creating lease {LeaseName}.");
.WithBodyAsJson(json));
await Awaiting(() => _underTest.ReadOrCreateLeaseResource(LeaseName)).Should()
.ThrowAsync<LeaseTimeoutException>()
.WithMessage($"Timed out creating lease {LeaseName}.*");
}
finally
{
Expand All @@ -304,30 +351,36 @@ 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))
.RespondWith(Response.Create()
.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<LeaseTimeoutException>();
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<LeaseTimeoutException>()
.WithMessage($"Timed out updating lease {LeaseName} to owner {owner}. It is not known if the update happened.*");
}
finally
{
Expand All @@ -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<LeaseTimeoutException>();
exception.Message.Should().StartWith($"Timed out removing lease {LeaseName}. It is not known if the remove happened.");

await Awaiting(() => _underTest.RemoveLease(LeaseName)).Should()
.ThrowAsync<LeaseTimeoutException>()
.WithMessage($"Timed out removing lease {LeaseName}. It is not known if the remove happened.*");
}
finally
{
Expand Down
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(LibraryFramework)</TargetFramework>
<TargetFrameworks>$(LibraryFramework);$(NetFramework)</TargetFrameworks>
<Description>Akka.NET coordination module for Kubernetes</Description>
<PackageTags>$(AkkaPackageTags);Kubernetes;</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -12,7 +12,14 @@
<PackageReference Include="Akka.Coordination" Version="$(AkkaVersion)" />
<PackageReference Include="Akka.Hosting" Version="$(AkkaHostingVersion)" />
<PackageReference Include="Akka.Cluster.Hosting" Version="$(AkkaHostingVersion)" />
<PackageReference Include="KubernetesClient" Version="$(KubernetesClientVersion)" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == '$(LibraryFramework)' ">
<PackageReference Include="KubernetesClient" Version="$(KubernetesClientVersionNetStandard)" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == '$(NetFramework)' ">
<PackageReference Include="KubernetesClient" Version="$(KubernetesClientVersionNet)" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 93a1996

Please sign in to comment.