Skip to content

IvanJosipovic/KubernetesCRDModelGen

Repository files navigation

KubernetesCRDModelGen

codecov

What is this?

This project contains components which allow generation of C# Classes/Assemblies from Kubernetes Custom Resource Definitions.

  • KubernetesCRDModelGen
    • Custom Resource Definition to C# Class/Assembly Generator
  • KubernetesCRDModelGen.SourceGenerator
    • Yaml to C# Source Generator
  • KubernetesCRDModelGen.Sync
    • Synchronizes Custom Resource Definitions from numerous sources

Published Packages

We publish the following premade packages

Group NuGet
argoproj.io Link
aws.upbound.io Link
azure.com Link
azure.upbound.io Link
cnrm.cloud.google.com Link
crossplane.io Link
fluxcd.io Link
gcp.upbound.io Link
helm.crossplane.io Link
istio.io Link
jetstack.io Link
keda.sh Link
knative.dev Link
kubevirt.io Link
projectcalico.org Link
secrets-store.csi.x-k8s.io Link
tf.upbound.io Link
traefik.io Link

Type Mappings

OpenAPIv3 type Type
'object' with Properties object
'object' with AdditionalProperties Dictionary
'object' with x-kubernetes-embedded-type object
'object' with x-kubernetes-preserve-unknown-fields object
'object' with x-kubernetes-int-or-string k8s.Models.IntstrIntOrString
'array' List
'array' with x-kubernetes-list-type=atomic List
'array' with x-kubernetes-list-type=map List
'array' with x-kubernetes-list-type=set List
'boolean' boolean
'number' (all formats) double
'integer' (all formats) int
'integer' with format=int64 long
'null' null
'string' string
'string' with format=binary bytes
'string' with format=byte (base64 encoded) bytes
'string' with format=date timestamp (google.protobuf.Timestamp)
'string' with format=date-time timestamp (google.protobuf.Timestamp)
'string' with format=duration duration (google.protobuf.Duration)

How to use the Source Generator

Create a C# Class Library Project and add some CRD yaml files to the project. Update the .csproj with the following settings. The Models will be generated in the "KubernetesCRDModelGen.Models.{CRD Group Name}" namespace.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="KubernetesCRDModelGen.SourceGenerator" Version="1.0.0-*" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
    <AdditionalFiles Include="*.yaml" />
  </ItemGroup>

</Project>