migrate to record (#1665)

* migrate to record

* chore: update project files and clean up unused references

* refactor: convert classes to records and simplify constructors for IntOrString, ResourceQuantity, and V1Patch

* fix: define IsExternalInit to resolve CS0518 error in IntOrString

* refactor: change IntOrString and ResourceQuantity from records to structs, update implicit conversions, and simplify null checks

* refactor: add JsonPropertyName attribute to Value property in IntOrString struct

* refactor: simplify V1Patch constructor and improve argument validation

* refactor: remove unnecessary CultureInfo parameter in ToInt method

* Update src/KubernetesClient/Models/ResourceQuantity.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/KubernetesClient/Models/IntOrString.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Revert "Update src/KubernetesClient/Models/ResourceQuantity.cs"

This reverts commit 62b20a691554659e28d419067220dc1a0620133b.

* refactor: remove commented-out formatting check and simplify build command

* refactor: remove IValidate.cs from project references in Aot and Classic

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Boshi Lian
2025-09-22 14:20:13 -07:00
committed by GitHub
parent 96955064cb
commit 5de1c25cf1
34 changed files with 215 additions and 454 deletions

View File

@@ -172,27 +172,33 @@ namespace k8s.E2E
using var kubernetes = CreateClient();
await kubernetes.CoreV1.CreateNamespacedEventAsync(
new Corev1Event(
new V1ObjectReference(
"v1alpha1",
kind: "Test",
name: "test",
namespaceProperty: "default",
resourceVersion: "1",
uid: "1"),
new V1ObjectMeta()
new Corev1Event
{
InvolvedObject = new V1ObjectReference
{
ApiVersion = "v1alpha1",
Kind = "Test",
Name = "test",
NamespaceProperty = "default",
ResourceVersion = "1",
Uid = "1",
},
Metadata = new V1ObjectMeta
{
GenerateName = "started-",
},
action: "STARTED",
type: "Normal",
reason: "STARTED",
message: "Started",
eventTime: DateTime.Now,
firstTimestamp: DateTime.Now,
lastTimestamp: DateTime.Now,
reportingComponent: "37",
reportingInstance: "38"), "default").ConfigureAwait(false);
Action = "STARTED",
Type = "Normal",
Reason = "STARTED",
Message = "Started",
EventTime = DateTime.Now,
FirstTimestamp = DateTime.Now,
LastTimestamp = DateTime.Now,
ReportingComponent = "37",
ReportingInstance = "38",
},
"default"
).ConfigureAwait(false);
}
[MinikubeFact]

View File

@@ -451,27 +451,33 @@ namespace k8s.E2E
using var kubernetes = CreateClient();
await kubernetes.CoreV1.CreateNamespacedEventAsync(
new Corev1Event(
new V1ObjectReference(
"v1alpha1",
kind: "Test",
name: "test",
namespaceProperty: "default",
resourceVersion: "1",
uid: "1"),
new V1ObjectMeta()
new Corev1Event
{
Metadata = new V1ObjectMeta
{
GenerateName = "started-",
NamespaceProperty = "default",
},
action: "STARTED",
type: "Normal",
reason: "STARTED",
message: "Started",
eventTime: DateTime.Now,
firstTimestamp: DateTime.Now,
lastTimestamp: DateTime.Now,
reportingComponent: "37",
reportingInstance: "38"), "default").ConfigureAwait(false);
InvolvedObject = new V1ObjectReference
{
ApiVersion = "v1alpha1",
Kind = "Test",
Name = "test",
NamespaceProperty = "default",
ResourceVersion = "1",
Uid = "1",
},
Action = "STARTED",
Type = "Normal",
Reason = "STARTED",
Message = "Started",
EventTime = DateTime.Now,
FirstTimestamp = DateTime.Now,
LastTimestamp = DateTime.Now,
ReportingComponent = "37",
ReportingInstance = "38",
},
"default").ConfigureAwait(false);
}
[MinikubeFact]

View File

@@ -7,7 +7,7 @@ using Xunit;
namespace k8s.tests;
public class BasicTests
public class SimpleTests
{
// TODO: fail to setup asp.net core 6 on net48
private class DummyHttpServer : System.IDisposable

View File

@@ -10,13 +10,13 @@ namespace k8s.Tests
{
{
var v = 123;
IntstrIntOrString intorstr = v;
IntOrString intorstr = v;
Assert.Equal("123", KubernetesJson.Serialize(intorstr));
}
{
IntstrIntOrString intorstr = "12%";
IntOrString intorstr = "12%";
Assert.Equal("\"12%\"", KubernetesJson.Serialize(intorstr));
}
}
@@ -25,12 +25,12 @@ namespace k8s.Tests
public void Deserialize()
{
{
var v = KubernetesJson.Deserialize<IntstrIntOrString>("1234");
var v = KubernetesJson.Deserialize<IntOrString>("1234");
Assert.Equal("1234", v.Value);
}
{
var v = KubernetesJson.Deserialize<IntstrIntOrString>("\"12%\"");
var v = KubernetesJson.Deserialize<IntOrString>("\"12%\"");
Assert.Equal("12%", v.Value);
}
}

View File

@@ -33,7 +33,7 @@ metadata:
}
#pragma warning disable CA1812 // Class is used for YAML deserialization tests
private class MyPod : V1Pod
private record MyPod : V1Pod
{
}
#pragma warning restore CA1812
@@ -531,7 +531,7 @@ spec:
var obj = new V1Service
{
Kind = "Service",
Metadata = new V1ObjectMeta(labels: labels, name: "test-svc"),
Metadata = new V1ObjectMeta { Name = "test-svc", Labels = labels },
ApiVersion = "v1",
Spec = new V1ServiceSpec
{