From 6e8166fb5c7ee63e76c720296af44a4b6ea0b8f8 Mon Sep 17 00:00:00 2001 From: Ian Buse Date: Wed, 1 Oct 2025 14:42:54 -0700 Subject: [PATCH 1/2] fix: Add special case for ResourceQuanitty transpilation fixes #958 --- src/KubeOps.Transpiler/Crds.cs | 3 +++ test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/KubeOps.Transpiler/Crds.cs b/src/KubeOps.Transpiler/Crds.cs index 17fb25f3..104f67b2 100644 --- a/src/KubeOps.Transpiler/Crds.cs +++ b/src/KubeOps.Transpiler/Crds.cs @@ -417,6 +417,9 @@ private static V1JSONSchemaProps MapObjectType(this MetadataLoadContext context, { switch (type.FullName) { + case "k8s.Models.ResourceQuantity": + // Quantities are serialized as strings in CRDs (e.g., "500m", "2Gi") + return new V1JSONSchemaProps { Type = String }; case "k8s.Models.V1ObjectMeta": return new V1JSONSchemaProps { Type = Object }; case "k8s.Models.IntstrIntOrString": diff --git a/test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs b/test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs index f3fcf09e..f9f595e7 100644 --- a/test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs +++ b/test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs @@ -37,6 +37,7 @@ public partial class CrdsMlcTest(MlcProvider provider) : TranspilerTestBase(prov [InlineData(typeof(DateTimeOffsetTestEntity), "string", "date-time", null)] [InlineData(typeof(NullableDateTimeOffsetTestEntity), "string", "date-time", true)] [InlineData(typeof(V1ObjectMetaTestEntity), "object", null, null)] + [InlineData(typeof(ResourceQuantityTestEntity), "string", null, null)] [InlineData(typeof(StringArrayEntity), "array", null, null)] [InlineData(typeof(NullableStringArrayEntity), "array", null, true)] [InlineData(typeof(EnumerableIntEntity), "array", null, null)] @@ -631,6 +632,12 @@ private class V1ObjectMetaTestEntity : CustomKubernetesEntity public V1ObjectMeta Property { get; set; } = null!; } + [KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")] + private class ResourceQuantityTestEntity: CustomKubernetesEntity + { + public ResourceQuantity Property { get; set; } = null!; + } + [KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")] private class StringArrayEntity : CustomKubernetesEntity { From adf3017a9859b0f448aca135bf5b9fbd9121f6b3 Mon Sep 17 00:00:00 2001 From: Ian Buse Date: Wed, 1 Oct 2025 14:55:56 -0700 Subject: [PATCH 2/2] linting: Add missing space --- test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs b/test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs index f9f595e7..db2e217f 100644 --- a/test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs +++ b/test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs @@ -633,7 +633,7 @@ private class V1ObjectMetaTestEntity : CustomKubernetesEntity } [KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")] - private class ResourceQuantityTestEntity: CustomKubernetesEntity + private class ResourceQuantityTestEntity : CustomKubernetesEntity { public ResourceQuantity Property { get; set; } = null!; }