Code Monkey home page Code Monkey logo

kubernetescrdmodelgen's Introduction

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
postgresql.cnpg.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-0" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
    <PackageReference Include="KubernetesCRDModelGen.Models" Version="1.0.0-0"/>
    <AdditionalFiles Include="*.yaml" />
  </ItemGroup>

</Project>

kubernetescrdmodelgen's People

Contributors

github-actions[bot] avatar ivanjosipovic avatar renovate[bot] avatar zeed-w-beez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kubernetescrdmodelgen's Issues

Cannot source generate CRD models because of error `Could not load file or assembly YamlDotNet`

Hello, I am trying to use the source generator in my project. I added the following lines in my csproj file

    <PackageReference Include="KubernetesCRDModelGen.SourceGenerator" Version="1.0.0-alpha.168" />
    <AdditionalFiles Include="<the path to my crd yaml" />

and run dotnet build, and then an error occurred

CSC : warning CS8785: Generator 'Generator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundExcep 
tion' with message 'Could not load file or assembly 'YamlDotNet, Version=13.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e'. The system cannot find the file specified.'

I tried to manually add YamlDotNet to my csproj but it didn't help. From the nuget site, the source generator doesn't have the dependency, but the dependency does show up in the csproj file of the source generate project. Is there any problem here?

Thanks!

Basic usage example

I've got a few existing CRDs in kubernetes. I'd like to be able to list those out, or find by name, and then pass one of them to KubernetesCRDModelGen in order to get class representation in C# that I can then use to create an instance of the CRD.

This project can do that yes?

If so, can you give an example of how to list out the CRDs initially in order to get one to pass to KubernetesCRDModelGen?

I've tried this but it wants to know what the CRD will be before I can loop through them:

// list out crds, looking for the specified crd
var generic = new GenericClient(Globals.service.kubeclient, "apiextensions.k8s.io", "v1", "customresourcedefinitions");

var crs = await generic.ListAsync<KubernetesObject>().ConfigureAwait(false);
foreach (var cr in crs.Items)

Renovate Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency fluentassertions to 6.12.1
  • chore(deps): update dependency kubernetesclient to v15
  • chore(deps): update dependency kubernetesclient.classic to v15
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/cicd.yaml
  • actions/checkout v4
  • cycjimmy/semantic-release-action v4
  • actions/setup-dotnet v4
  • codecov/codecov-action v4
  • cycjimmy/semantic-release-action v4
  • actions/upload-artifact v4
.github/workflows/sync-crds.yaml
  • actions/checkout v4
  • actions/setup-dotnet v4
  • azure/setup-helm v4
  • peter-evans/create-pull-request v6
nuget
benchmarks/KubernetesCRDModelGen.Benchmarks/KubernetesCRDModelGen.Benchmarks.csproj
  • BenchmarkDotNet 0.14.0
global.json
  • dotnet-sdk 8.0.401
src/KubernetesCRDModelGen.Models/KubernetesCRDModelGen.Models.csproj
  • Macross.Json.Extensions 3.0.0
  • KubernetesClient 14.0.9
  • KubernetesClient.Classic 14.0.9
src/KubernetesCRDModelGen.SourceGenerator/KubernetesCRDModelGen.SourceGenerator.csproj
  • Humanizer.Core 2.14.1
  • SharpYaml 2.1.1
  • Microsoft.OpenApi 1.6.17
  • Microsoft.OpenApi.Readers 1.6.17
  • System.Text.Encoding.CodePages 8.0.0
  • System.Reflection.Metadata 8.0.0
  • System.Collections.Immutable 8.0.0
  • Microsoft.CodeAnalysis.Common 4.11.0
  • Basic.Reference.Assemblies.NetStandard20 1.7.4
  • YamlDotNet 16.0.0
  • System.Security.Cryptography.Cng 5.0.0
  • Microsoft.CSharp 4.7.0
  • Microsoft.IdentityModel.Abstractions 8.0.1
  • Microsoft.IdentityModel.Logging 8.0.1
  • Microsoft.IdentityModel.Tokens 8.0.1
  • Microsoft.IdentityModel.JsonWebTokens 8.0.1
  • System.IdentityModel.Tokens.Jwt 8.0.1
  • System.Diagnostics.DiagnosticSource 8.0.1
  • System.ComponentModel.Annotations 5.0.0
  • Microsoft.Extensions.Primitives 8.0.0
  • Microsoft.Extensions.Options 8.0.2
  • Microsoft.Extensions.Logging.Abstractions 8.0.1
  • Microsoft.Extensions.DependencyInjection 8.0.0
  • Microsoft.Extensions.DependencyInjection.Abstractions 8.0.1
  • Microsoft.Extensions.Logging 8.0.0
  • System.Text.Encodings.Web 8.0.0
  • System.Numerics.Vectors 4.5.0
  • System.Memory 4.5.5
  • System.Buffers 4.5.1
  • System.Runtime.CompilerServices.Unsafe 6.0.0
  • System.Threading.Tasks.Extensions 4.5.4
  • Microsoft.Bcl.AsyncInterfaces 8.0.0
  • System.Text.Json 8.0.4
  • IdentityModel 7.0.0
  • IdentityModel.OidcClient 6.0.0
  • Fractions 8.0.3
  • BouncyCastle.Cryptography 2.4.0
  • KubernetesClient.Classic 14.0.9
  • Microsoft.CodeAnalysis.Analyzers 3.3.4
  • Microsoft.CodeAnalysis.CSharp 4.11.0
src/KubernetesCRDModelGen.Sync/KubernetesCRDModelGen.Sync.csproj
  • KubernetesClient 14.0.9
  • SharpZipLib 1.4.2
  • SemanticVersioning 2.0.2
  • Microsoft.Extensions.Http.Resilience 8.8.0
  • Microsoft.Extensions.Hosting 8.0.0
  • CliWrap 3.6.6
src/KubernetesCRDModelGen.Tests/KubernetesCRDModelGen.Tests.csproj
  • coverlet.collector 6.0.2
  • xunit.runner.visualstudio 2.8.2
  • xunit 2.9.0
  • System.Text.Json 8.0.4
  • Microsoft.NET.Test.Sdk 17.11.1
  • Microsoft.Extensions.Logging 8.0.0
  • Microsoft.Extensions.DependencyInjection 8.0.0
  • FluentAssertions 6.12.0
src/KubernetesCRDModelGen/KubernetesCRDModelGen.csproj
  • Basic.Reference.Assemblies.Net80 1.7.4
  • Basic.Reference.Assemblies.NetStandard20 1.7.4
  • Humanizer.Core 2.14.1
  • Microsoft.OpenApi.Readers 1.6.17
  • Microsoft.Extensions.Logging.Abstractions 8.0.1
  • Microsoft.CodeAnalysis.CSharp 4.11.0
src/Models/Directory.Build.props
src/Worker/Worker.csproj
  • Microsoft.Extensions.Hosting 8.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.