KubeOps.Transpiler
13.0.0
See the version list below for details.
dotnet add package KubeOps.Transpiler --version 13.0.0
NuGet\Install-Package KubeOps.Transpiler -Version 13.0.0
<PackageReference Include="KubeOps.Transpiler" Version="13.0.0" />
<PackageVersion Include="KubeOps.Transpiler" Version="13.0.0" />
<PackageReference Include="KubeOps.Transpiler" />
paket add KubeOps.Transpiler --version 13.0.0
#r "nuget: KubeOps.Transpiler, 13.0.0"
#:package KubeOps.Transpiler@13.0.0
#addin nuget:?package=KubeOps.Transpiler&version=13.0.0
#tool nuget:?package=KubeOps.Transpiler&version=13.0.0
KubeOps Transpiler
The KubeOps.Transpiler package provides utilities primarily focused on generating Kubernetes Custom Resource Definition (CRD) manifests (YAML/JSON) from .NET type definitions.
Note: This package is rarely used on its own. It is a logical part of the KubeOps operator framework and is typically used through the KubeOps CLI or as part of the operator build process.
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 = "demo.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
kubeops generate crdcommand. - 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.
CRD Schema Validation
The transpiler performs a narrow validation pass for schema attributes that are
known to produce CRDs rejected by the Kubernetes API server. This includes
uniqueItems: true, invalid x-kubernetes-list-* topology combinations,
invalid x-kubernetes-map-type placement, and malformed validation-rule
metadata. Additional printer columns are also checked so their type is one of
the Kubernetes-supported column types.
The transpiler does not try to be a full OpenAPI linter. Some OpenAPI keywords are semantically useful only on specific schema types, but Kubernetes currently accepts those CRD schemas at admission time. Those combinations remain transpilable for compatibility.
For a server-side check against a local cluster, generate manifests and use Kubernetes server dry-run for the generated CRD YAML files:
kubeops generate operator MyOperator ./MyOperator.csproj --out ./k8s --format yaml
kubectl apply --dry-run=server -f ./k8s/<generated-crd-file>.yaml
The assembly inspection and attribute processing logic within this package is also leveraged by the KubeOps CLI (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.
| Product | Versions 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. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- KubeOps.Abstractions (>= 13.0.0)
- System.Reflection.MetadataLoadContext (>= 10.0.9)
-
net8.0
- KubeOps.Abstractions (>= 13.0.0)
- System.Reflection.MetadataLoadContext (>= 10.0.9)
-
net9.0
- KubeOps.Abstractions (>= 13.0.0)
- System.Reflection.MetadataLoadContext (>= 10.0.9)
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 |
|---|---|---|
| 13.1.0-prerelease.2 | 36 | 7/17/2026 |
| 13.1.0-prerelease.1 | 50 | 7/16/2026 |
| 13.0.0 | 426 | 7/14/2026 |
| 13.0.0-prerelease.6 | 59 | 7/14/2026 |
| 13.0.0-prerelease.5 | 65 | 7/12/2026 |
| 13.0.0-prerelease.4 | 70 | 7/11/2026 |
| 13.0.0-prerelease.3 | 78 | 7/11/2026 |
| 13.0.0-prerelease.2 | 61 | 7/11/2026 |
| 13.0.0-prerelease.1 | 76 | 7/11/2026 |
| 12.1.0-prerelease.1 | 70 | 7/10/2026 |
| 12.0.1-prerelease.2 | 75 | 7/9/2026 |
| 12.0.1-prerelease.1 | 66 | 7/8/2026 |
| 12.0.0 | 720 | 7/7/2026 |
| 11.6.0-prerelease.1 | 73 | 7/3/2026 |
| 11.5.1-prerelease.2 | 72 | 7/2/2026 |
| 11.5.1-prerelease.1 | 70 | 7/2/2026 |
| 11.5.0 | 2,218 | 6/30/2026 |
| 11.5.0-prerelease.6 | 73 | 6/28/2026 |
| 11.5.0-prerelease.5 | 67 | 6/28/2026 |
| 11.5.0-prerelease.4 | 85 | 6/27/2026 |
'## [13.0.0](https://github.com/dotnet/dotnet-operator-sdk/compare/v12.0.0...v13.0.0) (2026-07-14)
### ⚠ BREAKING CHANGES
* **operator:** add enriched entity logging scopes (#1196)
* **operator:** add scoped leader election (#1192)
* **generator:** support multi-assembly component composition (#1188)
* **operator:** support multiple controllers and selectors per entity (#1183)
### Features
* **generator:** support multi-assembly component composition ([#1188](https://github.com/dotnet/dotnet-operator-sdk/issues/1188)) ([443ed18](https://github.com/dotnet/dotnet-operator-sdk/commit/443ed18625e34c62f68d4d4e88be762ee534975c))
* **operator:** add enriched entity logging scopes ([#1196](https://github.com/dotnet/dotnet-operator-sdk/issues/1196)) ([e545bf8](https://github.com/dotnet/dotnet-operator-sdk/commit/e545bf8e2f6628369bf19705556450bd8feccb87))
* **operator:** add scoped leader election ([#1192](https://github.com/dotnet/dotnet-operator-sdk/issues/1192)) ([621ca2a](https://github.com/dotnet/dotnet-operator-sdk/commit/621ca2a83d7230451a512504b2739a530e733942))
* **operator:** support multiple controllers and selectors per entity ([#1183](https://github.com/dotnet/dotnet-operator-sdk/issues/1183)) ([80d064c](https://github.com/dotnet/dotnet-operator-sdk/commit/80d064cbc8e9ed9ab67edb15acd360a2e4773e06))
* **transpiler:** add schema validation for CRD attributes ([#1165](https://github.com/dotnet/dotnet-operator-sdk/issues/1165)) ([0f7aac7](https://github.com/dotnet/dotnet-operator-sdk/commit/0f7aac722de9e0251c3ec1f23cf151a6ffa986e7))
### Bug Fixes
* **operator-web:** compose conversions through the storage version ([#1194](https://github.com/dotnet/dotnet-operator-sdk/issues/1194)) ([bc975aa](https://github.com/dotnet/dotnet-operator-sdk/commit/bc975aae93571dd4961610766337b8bb49990694))
### Dependencies
* **ci:** update dependency semantic-release to v25.0.6 ([#1189](https://github.com/dotnet/dotnet-operator-sdk/issues/1189)) ([a83e7c2](https://github.com/dotnet/dotnet-operator-sdk/commit/a83e7c2fb9e235203ecfe2f0a3a7f7e27c6bfe38))
* **ci:** update dependency semantic-release to v25.0.7 ([#1195](https://github.com/dotnet/dotnet-operator-sdk/issues/1195)) ([c5e2460](https://github.com/dotnet/dotnet-operator-sdk/commit/c5e2460f745d3eca5fa949b8d0fe0152297114b7))
* **core:** update dependency messagepack to 3.1.8 ([#1186](https://github.com/dotnet/dotnet-operator-sdk/issues/1186)) ([a449070](https://github.com/dotnet/dotnet-operator-sdk/commit/a44907017ad8ee2d315242afb9a932071f3343ac))
* **core:** update dependency opentelemetry.instrumentation.runtime to 1.16.0 ([#1187](https://github.com/dotnet/dotnet-operator-sdk/issues/1187)) ([4629d17](https://github.com/dotnet/dotnet-operator-sdk/commit/4629d17633f3b0fa5eb649bc4e6e910672ac4276))
* **core:** update dependency sonaranalyzer.csharp to 10.29.0.143774 ([#1191](https://github.com/dotnet/dotnet-operator-sdk/issues/1191)) ([72a0d87](https://github.com/dotnet/dotnet-operator-sdk/commit/72a0d872a7be1ad9fb30a18da30323d4d3a8bea7))
* **docs:** update docusaurus monorepo to v3.10.2 ([#1190](https://github.com/dotnet/dotnet-operator-sdk/issues/1190)) ([5c88c18](https://github.com/dotnet/dotnet-operator-sdk/commit/5c88c186be0917217456ab512ac7a0aae15e62db))
### Documentation
* **operator:** revise migration guide for v12 upgrades ([#1185](https://github.com/dotnet/dotnet-operator-sdk/issues/1185)) ([72a24b7](https://github.com/dotnet/dotnet-operator-sdk/commit/72a24b782cf1c53d225bbfdbf862ce9786512c8b))
'