Reverse the KubeOpsSkipCrds... logic to support custom resource libraries? #355
Replies: 5 comments 14 replies
-
Hey @jefflill This could be an option yes! What do others think about this change? (since it would be a breaking change) |
Beta Was this translation helpful? Give feedback.
-
KubeOps ROCKS! I got my first production operator working yesterday using KubeOps and .NET. One additional related idea: It would be nice if the CRD related classes and attributes like:
were published as separate netstandard2.0 nuget package. This would be much cleaner for folks writing libraries with custom resource classes (like us). It's a bit weird to force all consumers of these libraries to also be .NET 6 (although this is the future of course). |
Beta Was this translation helpful? Give feedback.
-
That's not entirely true. .NET Standard 2.0 and 2.1 libraries still work for .NET 5/6 and there are still a lot of people with legacy .NET 3.1 apps as well. For example, the KubernetesClient nuget package actually includes .NET Standard 2.0 in addition to .NET 5 and .NET 6 versions. The nice thing here all legacy application from, .NET 3.1 and later are all supported. https://www.nuget.org/packages/KubernetesClient/ So there are actually two reasons for splitting the custom resource related classes into a separate .NET Standard 2.1 library:
The problem here is that your KubeOps package includes all of the ASP.NET code which doesn't really make sense for client (non-operator) apps that are just making calls to the API server. Imagine the extreme case of an iPhone app written in MAUI that just needs to retrieve some cluster status. It would be really unfortunate to require the phone app to include the entire ASP.NET stack just to be able use the Kubernetes client to query an API server. Over at neonKUBE, we have a similar situation with a command line client that needs to perform operations on custom resources handled by an operator implemented with your SDK. That tool ends up with ASP.NET even though it's never used. |
Beta Was this translation helpful? Give feedback.
-
One thing that came up: if we split the core out of the operator and publish it as .net6 and .netstandard2.1 lib, the generator must reside in the operator sdk library. The code generator (yaml stuff) cannot be separate since it needs access to the code in the project. It uses Assembly scanning to fetch types with the KubernetesEntity attribute to generate the CRDs and other things. One possibility to solve this with an external tool would be to load the compiled assembly of the operator. Correct? |
Beta Was this translation helpful? Give feedback.
-
Hey all :) Has been a while. Hope you all are doing well! I create a new branch to work on when I got the time: https://github.com/buehler/dotnet-operator-sdk/tree/refactor/new-setup What do you think about the setup? This would result in more packages, however, the possibility exists to create operators without web components (asp) and use the generators outside the same lib. The core should be one lib (.netstandard or .net 6/7/8, don't know yet). |
Beta Was this translation helpful? Give feedback.
-
We've started to integrate your SDK into a multiple project solution and we'd like to implement a library of resources that can be shared by multiple projects. Here's how this is working now:
We create a Resources library project that references KubeOps and is where we define our custom resources. We add the
<KubeoOpsSkip...>true</KubeoOpsSkip...>
elements to the library's .csproj to prevent your build targets from trying to execute the library to perform generate the CRDs, etc. (which won't work of course, because it's just a library, not a console app).We currently implementing two operators, one that runs as a daemonset on all cluster nodes and the other as a regular deployment. I have one of these configured to generate CRDs (via your build targets) and we have these installed by Helm when we install this operator into the cluster. The other operator and any subsequent operators won't generate or install CRDs.
Other (non-operator) projects also reference the Resources library to add and manage custom resources to the cluster.
The problem we're seeing is that your build targets are executed for every project that references KubeOps, even those with indirect references. This means that we need add
<KubeoOpsSkip...>true</KubeoOpsSkip...>
elements to every library or console project that references anything else that references KubeOps, which is a hassle and would be inconvenient for any innocent developer who wanted to import a custom resource library via nuget.I wonder if it would be possible to reverse your logic to allow people to explicitly opt-in (rather then opting-out) to the CRD, etc... generation via something like?
...and then update your project templates to include this.
The nice thing about this approach would be that it'll still just-work for operator projects and library and non-operator projects wouldn't have to do anything special to prevent the generator calls from breaking the build.
Beta Was this translation helpful? Give feedback.
All reactions