From 87397c8735e1c0be73781049c3cf1ca16c39e4d4 Mon Sep 17 00:00:00 2001 From: Patrick Evers Date: Wed, 26 Mar 2025 11:14:59 +0100 Subject: [PATCH 1/4] Allow Nullable Status --- src/K8sOperator.NET/Models/CustomResource.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/K8sOperator.NET/Models/CustomResource.cs b/src/K8sOperator.NET/Models/CustomResource.cs index 6ea901b..4134843 100644 --- a/src/K8sOperator.NET/Models/CustomResource.cs +++ b/src/K8sOperator.NET/Models/CustomResource.cs @@ -35,7 +35,7 @@ public abstract class CustomResource : CustomResource, ISpec /// /// The type of the specification. /// The type of the status. -public abstract class CustomResource : CustomResource, IStatus +public abstract class CustomResource : CustomResource, IStatus where TSpec : new() where TStatus : new() { @@ -43,5 +43,5 @@ public abstract class CustomResource : CustomResource, IS /// Gets or sets the status for the custom resource. /// [JsonPropertyName("status")] - public TStatus Status { get; set; } = new(); + public TStatus? Status { get; set; } } From 995c091a218c5ac6ccc3d66fdc42a367d046c8a1 Mon Sep 17 00:00:00 2001 From: Patrick Evers Date: Wed, 26 Mar 2025 11:21:10 +0100 Subject: [PATCH 2/4] Update Tests --- test/K8sOperator.NET.Tests/ControllerTests.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/K8sOperator.NET.Tests/ControllerTests.cs b/test/K8sOperator.NET.Tests/ControllerTests.cs index dbe9bb2..34810f3 100644 --- a/test/K8sOperator.NET.Tests/ControllerTests.cs +++ b/test/K8sOperator.NET.Tests/ControllerTests.cs @@ -1,4 +1,5 @@ -using K8sOperator.NET.Models; +using IdentityModel.Client; +using K8sOperator.NET.Models; namespace K8sOperator.NET.Tests; @@ -79,8 +80,9 @@ public async Task Overridden_AddOrModifyAsync_Should_Call_CustomImplementation() // Act await derivedController.AddOrModifyAsync(resource, CancellationToken.None); - // Assert - resource.Status.Status.Should().Be("Changed"); + + resource.Status.Should().NotBeNull(); + resource.Status?.Status.Should().Be("Changed"); } // You can also extend these tests for DeleteAsync, FinalizeAsync, BookmarkAsync, and ErrorAsync From 6f80a39bc877589d2efaf8652c56f855686c7788 Mon Sep 17 00:00:00 2001 From: Patrick Evers Date: Wed, 26 Mar 2025 11:23:15 +0100 Subject: [PATCH 3/4] Remove new() Constraint --- src/K8sOperator.NET/Models/CustomResource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/K8sOperator.NET/Models/CustomResource.cs b/src/K8sOperator.NET/Models/CustomResource.cs index 4134843..3c79cdc 100644 --- a/src/K8sOperator.NET/Models/CustomResource.cs +++ b/src/K8sOperator.NET/Models/CustomResource.cs @@ -37,7 +37,7 @@ public abstract class CustomResource : CustomResource, ISpec /// The type of the status. public abstract class CustomResource : CustomResource, IStatus where TSpec : new() - where TStatus : new() + where TStatus : class { /// /// Gets or sets the status for the custom resource. From 2df437495751c04b63ea62ca4ebe4a743e9e20ba Mon Sep 17 00:00:00 2001 From: Patrick Evers Date: Wed, 26 Mar 2025 11:31:47 +0100 Subject: [PATCH 4/4] Remove unused namespaces --- test/K8sOperator.NET.Tests/ControllerTests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/K8sOperator.NET.Tests/ControllerTests.cs b/test/K8sOperator.NET.Tests/ControllerTests.cs index 34810f3..e37dc09 100644 --- a/test/K8sOperator.NET.Tests/ControllerTests.cs +++ b/test/K8sOperator.NET.Tests/ControllerTests.cs @@ -1,7 +1,4 @@ -using IdentityModel.Client; -using K8sOperator.NET.Models; - -namespace K8sOperator.NET.Tests; +namespace K8sOperator.NET.Tests; public class ControllerTests {