KubeOps.Transpiler 9.5.0

dotnet add package KubeOps.Transpiler --version 9.5.0
                    
NuGet\Install-Package KubeOps.Transpiler -Version 9.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KubeOps.Transpiler" Version="9.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KubeOps.Transpiler" Version="9.5.0" />
                    
Directory.Packages.props
<PackageReference Include="KubeOps.Transpiler" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KubeOps.Transpiler --version 9.5.0
                    
#r "nuget: KubeOps.Transpiler, 9.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=KubeOps.Transpiler&version=9.5.0
                    
Install KubeOps.Transpiler as a Cake Addin
#tool nuget:?package=KubeOps.Transpiler&version=9.5.0
                    
Install KubeOps.Transpiler as a Cake Tool

KubeOps Transpiler

Nuget

The KubeOps.Transpiler package provides utilities primarily focused on generating Kubernetes Custom Resource Definition (CRD) manifests (YAML/JSON) from .NET type definitions.

It allows you to define your custom resources using C# classes and attributes, and then automatically create the corresponding Kubernetes CRD schema required to register your resource type with the cluster.

The output is standard Kubernetes YAML/JSON, suitable for use with kubectl apply or any Kubernetes tooling.

Installation

The package is available on NuGet:

dotnet add package KubeOps.Transpiler

Usage

The core functionality revolves around inspecting .NET assemblies and their types to find entities marked for Kubernetes and converting their structure into a CRD format.

Generating CRDs

You can transpile .NET types decorated with the [KubernetesEntity] attribute (defined in KubeOps.Abstractions) into V1CustomResourceDefinition objects from the official Kubernetes client library.

This process involves inspecting your C# class properties and translating them into an OpenAPI v3 schema embedded within the CRD. The transpiler utilizes standard .NET attributes on your entity properties (e.g., System.ComponentModel attributes like [Description], [Required], [Range], and validation attributes like [MinLength], [MaxLength], [RegularExpression]) to generate richer schema information. This schema is crucial as it enables:

  • kubectl explain <your-kind>.<your-group>
  • Server-side validation by the Kubernetes API server when resources are created or updated.

This process often utilizes System.Reflection.MetadataLoadContext to inspect assemblies without fully loading or executing them, which is useful in build-time tools or CLIs.

Using MetadataLoadContext allows inspection without loading the assembly and its potentially conflicting dependencies into the current application domain, making it ideal for build-time tools and CLIs.

Example:

using k8s.Models;
using KubeOps.Abstractions.Entities;
using KubeOps.Transpiler;
using System.Reflection;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

// Define your custom resource class (usually in a separate project)
[KubernetesEntity(Group = "ewassef.dev", ApiVersion = "v1alpha1", Kind = "MyResource")]
public class MyCustomResource : CustomKubernetesEntity
{
    public MyCustomResourceSpec Spec { get; set; } = new();
}

public class MyCustomResourceSpec
{
    public string? Message { get; set; }
    public int Replicas { get; set; }
}

// --- Transpilation Logic (e.g., in a build task or utility) ---

// 1. Get the assembly containing your custom resource types
//    (Adjust path as needed or use Assembly.LoadFrom/Assembly.Load)
var assemblyPath = "path/to/your/Operator.Project.dll";
var assembly = Assembly.LoadFrom(assemblyPath);

// 2. Create a MetadataLoadContext
//    Provide assembly resolver paths (e.g., NuGet package directories)
//    Needed for resolving base types and attributes from referenced assemblies.
var resolver = new PathAssemblyResolver(Directory.GetFiles(Path.GetDirectoryName(assemblyPath)!, "*.dll"));
using var mlc = new MetadataLoadContext(resolver);
var assemblyInMlc = mlc.LoadFromAssemblyPath(assemblyPath);

// 3. Transpile types from the assembly
var crds = assemblyInMlc.GetCustomResourceDefinitions(); // KubeOps.Transpiler extension method

// 4. (Optional) Serialize to YAML
var serializer = new SerializerBuilder()
    .WithNamingConvention(CamelCaseNamingConvention.Instance) // Common for Kubernetes YAML
    .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults) // Reduce YAML size
    .Build();

foreach (var crd in crds)
{
    var crdYaml = serializer.Serialize(crd);
    Console.WriteLine("---"); // YAML document separator
    Console.WriteLine(crdYaml);
    // Or write to a file, e.g., File.WriteAllText($"{crd.Metadata.Name}.crd.yaml", crdYaml);
}

### Use Cases

*   **KubeOps CLI:** This package is the engine behind the `dotnet kubeops generate crd` command.
*   **Custom Build Tasks:** Integrate CRD generation directly into your MSBuild process.
*   **Schema Validation Tools:** Use the generated CRD schema for validating custom resource YAML files.

The assembly inspection and attribute processing logic within this package is also leveraged by the KubeOps CLI (`dotnet kubeops generate operator`) command. The CLI uses this package's capabilities to find types decorated with `[EntityRbac]` attributes when generating the RBAC manifests (`Role`/`ClusterRole`) for your operator.

For more details on defining the C# classes themselves, see the main KubeOps documentation on [Custom Entities](../../docs/custom-entities.md).
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on KubeOps.Transpiler:

Package Downloads
KubeOps.KubernetesClient

Kubernetes Client written in DotNet. Based on the implementation of Google (https://github.com/kubernetes-client/csharp) but with dotnet native language features like generics. Internally uses the "GenericClient" of the Google KubernetesClient. However, wraps the methods around with true generics.

KubeOps.Operator

This is an operator sdk written in c#. It enables a developer to create a custom controller for CRDs (CustomResourceDefinitions) that runs on kubernetes. This operator may run without ASP.net but needs the IHost of dotnet to run.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.5.0 283 5/8/2025
9.4.1 918 4/29/2025
9.4.0 266 4/28/2025
9.3.0 6,448 3/26/2025
9.2.0 11,063 1/24/2025
9.1.5 43,916 9/10/2024
9.1.4 1,608 8/26/2024
9.1.3 20,638 6/28/2024
9.1.2 11,186 6/20/2024
9.1.1 5,768 5/22/2024
9.1.0 2,661 5/15/2024
9.0.2 285 5/13/2024
9.0.0 29,022 3/13/2024
9.0.0-pre.4 82 4/19/2024
9.0.0-pre.3 79 3/21/2024
9.0.0-pre.2 68 3/13/2024
9.0.0-pre.1 92 3/7/2024
8.0.2-pre.2 93 2/21/2024
8.0.2-pre.1 72 2/19/2024
8.0.1 11,761 2/13/2024
8.0.1-pre.7 86 2/12/2024
8.0.1-pre.6 78 2/7/2024
8.0.1-pre.5 71 2/5/2024
8.0.1-pre.4 77 1/31/2024
8.0.1-pre.3 79 1/26/2024
8.0.1-pre.2 76 1/25/2024
8.0.1-pre.1 79 1/18/2024
8.0.0 1,125 1/17/2024
8.0.0-pre.45 70 1/17/2024
8.0.0-pre.44 76 1/16/2024
8.0.0-pre.43 77 1/16/2024
8.0.0-pre.42 904 1/10/2024
8.0.0-pre.41 304 1/2/2024
8.0.0-pre.40 178 12/27/2023
8.0.0-pre.39 89 12/21/2023
8.0.0-pre.38 432 12/6/2023
8.0.0-pre.37 137 12/6/2023
8.0.0-pre.36 160 12/3/2023
8.0.0-pre.35 116 11/28/2023
8.0.0-pre.34 124 11/24/2023
8.0.0-pre.33 80 11/24/2023
8.0.0-pre.32 84 11/23/2023
8.0.0-pre.31 84 11/23/2023
8.0.0-pre.30 97 11/23/2023
8.0.0-pre.29 984 11/11/2023
8.0.0-pre.28 104 11/8/2023
8.0.0-pre.27 578 10/23/2023
8.0.0-pre.26 113 10/19/2023
8.0.0-pre.25 81 10/18/2023
8.0.0-pre.24 93 10/13/2023
8.0.0-pre.23 83 10/13/2023
8.0.0-pre.22 92 10/13/2023
8.0.0-pre.21 91 10/12/2023
8.0.0-pre.20 82 10/11/2023
8.0.0-pre.19 91 10/9/2023
8.0.0-pre.18 78 10/9/2023
8.0.0-pre.17 83 10/7/2023
8.0.0-pre.16 79 10/6/2023
8.0.0-pre.15 83 10/6/2023
8.0.0-pre.14 84 10/5/2023
8.0.0-pre.13 76 10/5/2023
8.0.0-pre.12 83 10/4/2023
8.0.0-pre.11 97 10/3/2023
8.0.0-pre.10 88 10/3/2023
8.0.0-pre.9 90 10/3/2023
8.0.0-pre.8 86 10/2/2023
8.0.0-pre.7 89 10/2/2023
8.0.0-pre.6 86 9/29/2023
8.0.0-pre.5 84 9/28/2023
8.0.0-pre.4 82 9/28/2023
8.0.0-pre.3 80 9/27/2023
8.0.0-pre.2 70 9/26/2023
8.0.0-pre.1 73 9/22/2023

'# [9.5.0](https://github.com/buehler/dotnet-operator-sdk/compare/v9.4.1...v9.5.0) (2025-05-08)


### Bug Fixes

* Change the labels to an array ([#881](https://github.com/buehler/dotnet-operator-sdk/issues/881)) ([4e0c205](https://github.com/buehler/dotnet-operator-sdk/commit/4e0c2054f9a6bc10ac694c04c68e518c1357c687)), closes [/#diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L39-R45](https://github.com///issues/diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L39-R45) [/#diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L54-R62](https://github.com///issues/diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L54-R62) [/#diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L74-R109](https://github.com///issues/diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L74-R109) [/#diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L159-R159](https://github.com///issues/diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L159-R159) [/#diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L170-R174](https://github.com///issues/diff-cf95f5a9676479797ff0ade11e4dd8d679dd1974142058976f3a35ca6a63b4f2L170-R174)
* **deps:** update dependencies ([#853](https://github.com/buehler/dotnet-operator-sdk/issues/853)) ([5a99011](https://github.com/buehler/dotnet-operator-sdk/commit/5a99011c33bc87daa49e7ce1c8d7d4fb62663ed9))
* **deps:** update dependency sonaranalyzer.csharp to 10.9.0.115408 ([#878](https://github.com/buehler/dotnet-operator-sdk/issues/878)) ([74c0a66](https://github.com/buehler/dotnet-operator-sdk/commit/74c0a66e502431d4f372d32b6d118e9f7d9426fa))


### Features

* Add `AllExplicit` RBAC verb & state all default V1Lease RBAC verbs explicitly ([#879](https://github.com/buehler/dotnet-operator-sdk/issues/879)) ([92063d8](https://github.com/buehler/dotnet-operator-sdk/commit/92063d8b7a8f5d45f6c79e0e1a85101370679255))



'