Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generating CRD's for entities that contain other custom resources #823

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace KubeOps.Abstractions.Entities.Attributes;

/// <summary>
/// Defines a description for a property. This precedes the description found in a
/// XML documentation file.
/// Defines a description for a property.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)]
public class DescriptionAttribute(string description) : Attribute
Expand Down
5 changes: 5 additions & 0 deletions src/KubeOps.Transpiler/Crds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ private static V1JSONSchemaProps Map(this MetadataLoadContext context, Type type
return context.MapEnumerationType(type, interfaces);
}

if (type.BaseType?.Name == nameof(CustomKubernetesEntity) || type.BaseType?.Name == typeof(CustomKubernetesEntity<>).Name)
{
return context.MapObjectType(type);
}

return type.BaseType?.FullName switch
{
"System.Object" => context.MapObjectType(type),
Expand Down
26 changes: 26 additions & 0 deletions test/KubeOps.Transpiler.Test/Crds.Mlc.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class CrdsMlcTest(MlcProvider provider) : TranspilerTestBase(provider)
[InlineData(typeof(EnumerableKeyPairsEntity), "object", null, false)]
[InlineData(typeof(IntstrOrStringEntity), null, null, false)]
[InlineData(typeof(EmbeddedResourceEntity), "object", null, false)]
[InlineData(typeof(EmbeddedCustomResourceEntity), "object", null, false)]
[InlineData(typeof(EmbeddedCustomResourceGenericEntity), "object", null, false)]
[InlineData(typeof(EmbeddedResourceListEntity), "array", null, false)]
public void Should_Transpile_Entity_Type_Correctly(Type type, string? expectedType, string? expectedFormat,
bool isNullable)
Expand Down Expand Up @@ -687,6 +689,30 @@ private class EmbeddedResourceEntity : CustomKubernetesEntity
public V1Pod Property { get; set; } = null!;
}

[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
private class EmbeddedCustomResourceEntity : CustomKubernetesEntity
{
public EmbeddedCustomResource Property { get; set; } = null!;
}

[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
private class EmbeddedCustomResource : CustomKubernetesEntity
{
public string Property { get; set; } = string.Empty;
}

[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
private class EmbeddedCustomResourceGenericEntity : CustomKubernetesEntity
{
public EmbeddedCustomResourceGeneric Property { get; set; } = null!;
}

[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
private class EmbeddedCustomResourceGeneric : CustomKubernetesEntity<EmbeddedCustomResourceGeneric.EntitySpec>
{
public class EntitySpec;
}

[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
private class EmbeddedResourceListEntity : CustomKubernetesEntity
{
Expand Down
Loading