KubeOps.Operator
8.0.0-pre.34
See the version list below for details.
dotnet add package KubeOps.Operator --version 8.0.0-pre.34
NuGet\Install-Package KubeOps.Operator -Version 8.0.0-pre.34
<PackageReference Include="KubeOps.Operator" Version="8.0.0-pre.34" />
paket add KubeOps.Operator --version 8.0.0-pre.34
#r "nuget: KubeOps.Operator, 8.0.0-pre.34"
// Install KubeOps.Operator as a Cake Addin #addin nuget:?package=KubeOps.Operator&version=8.0.0-pre.34&prerelease // Install KubeOps.Operator as a Cake Tool #tool nuget:?package=KubeOps.Operator&version=8.0.0-pre.34&prerelease
KubeOps Operator
The KubeOps.Operator
package provides a framework
for building Kubernetes operators in .NET.
It is built on top of the Kubernetes client libraries for .NET
and provides a set of abstractions and utilities for implementing
operators that manage custom resources in a Kubernetes cluster.
Getting Started
To get started with the SDK, you can install it from NuGet:
dotnet add package KubeOps.Operator
Once you have installed the package, you can create entities, controllers, finalizers, and more to implement your operator.
All resources must be added to the operator builder in order to be recognized by the SDK and to be used as operator resources. The KubeOps.Generator helps with convenience methods to register everything at once.
You'll need to use the Generic Host to run your operator. However, for a plain operator without webhooks, no ASP.net is required (in contrast to v7).
using KubeOps.Operator.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Services
.AddKubernetesOperator()
.RegisterComponents();
using var host = builder.Build();
await host.RunAsync();
Registering Resources
When using the KubeOps.Generator,
you can use the RegisterResources
function:
builder.Services
.AddKubernetesOperator()
.RegisterComponents();
Otherwise, you can register resources manually:
builder.Services
.AddKubernetesOperator()
.AddController<TestController, V1TestEntity>()
.AddFinalizer<FirstFinalizer, V1TestEntity>("first")
.AddFinalizer<SecondFinalizer, V1TestEntity>("second")
Entity
To create an entity, you need to implement the
IKubernetesObject<V1ObjectMeta>
interface. There are convenience
classes available to help with initialization, status and spec
properties.
[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
public class V1TestEntity :
CustomKubernetesEntity<V1TestEntity.EntitySpec, V1TestEntity.EntityStatus>
{
public override string ToString()
=> $"Test Entity ({Metadata.Name}): {Spec.Username} ({Spec.Email})";
public class EntitySpec
{
public string Username { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
}
public class EntityStatus
{
public string Status { get; set; } = string.Empty;
}
}
Controller
A controller is the element that reconciles a specific entity. You can reconcile your own custom entities or all other entities as long as they are registered within the SDK. For a guide on how to reconcile external entities, refer to the documentation.
A simple controller could look like this:
[EntityRbac(typeof(V1TestEntity), Verbs = RbacVerb.All)]
public class V1TestEntityController : IEntityController<V1TestEntity>
{
private readonly IKubernetesClient _client;
private readonly EntityFinalizerAttacher<FinalizerOne, V1TestEntity> _finalizer1;
public V1TestEntityController(
IKubernetesClient client,
EntityFinalizerAttacher<FinalizerOne, V1TestEntity> finalizer1)
{
_client = client;
_finalizer1 = finalizer1;
}
public async Task ReconcileAsync(V1TestEntity entity)
{
_logger.LogInformation("Reconciling entity {Entity}.", entity);
entity = await _finalizer1(entity);
entity.Status.Status = "Reconciling";
entity = await _client.UpdateStatus(entity);
entity.Status.Status = "Reconciled";
await _client.UpdateStatus(entity);
}
}
This controller attaches a specific finalizer to the entity, updates its status and then saves the entity.
[!CAUTION] It is important to always use the returned values of an entity when using modifying actions of the Kubernetes client. Otherwise, you will receive "HTTP CONFLICT" errors because of the resource version field in the entity.
[!NOTE] Do not update the entity itself in the reconcile loop. It is considered bad practice to update entities while reconciling them. However, the status may be updated. To update entities before they are reconciled (e.g. to ban certain values or change values), use webhooks instead.
Finalizer
A finalizer is an element for asynchronous cleanup in Kubernetes.
It is attached with an EntityFinalizerAttacher
and is called
when the entity is marked as deleted.
public class FinalizerOne : IEntityFinalizer<V1TestEntity>
{
public Task FinalizeAsync(V1TestEntity entity)
{
return Task.CompletedTask;
}
}
[!NOTE] The controller (if you overwrote the
DeletedAsync
method) will receive the notification as soon as all finalizers are removed.
Documentation
For more information, please visit the documentation.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- KubeOps.Abstractions (>= 8.0.0-pre.34)
- KubeOps.KubernetesClient (>= 8.0.0-pre.34)
- KubeOps.Transpiler (>= 8.0.0-pre.34)
- Microsoft.Extensions.Hosting (>= 8.0.0)
-
net7.0
- KubeOps.Abstractions (>= 8.0.0-pre.34)
- KubeOps.KubernetesClient (>= 8.0.0-pre.34)
- KubeOps.Transpiler (>= 8.0.0-pre.34)
- Microsoft.Extensions.Hosting (>= 8.0.0)
-
net8.0
- KubeOps.Abstractions (>= 8.0.0-pre.34)
- KubeOps.KubernetesClient (>= 8.0.0-pre.34)
- KubeOps.Transpiler (>= 8.0.0-pre.34)
- Microsoft.Extensions.Hosting (>= 8.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on KubeOps.Operator:
Package | Downloads |
---|---|
KubeOps.Operator.Web
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 uses ASP.net to support webhooks and external access to the operator. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on KubeOps.Operator:
Repository | Stars |
---|---|
josephnhtam/live-streaming-server-net
A .NET implementation of RTMP live streaming server, supporting HTTP-FLV, WebSocket-FLV, HLS, Kubernetes, cloud storage services integration and more.
|
Version | Downloads | Last updated |
---|---|---|
9.1.5 | 11,335 | 9/10/2024 |
9.1.4 | 1,121 | 8/26/2024 |
9.1.3 | 11,807 | 6/28/2024 |
9.1.2 | 8,041 | 6/20/2024 |
9.1.1 | 4,450 | 5/22/2024 |
9.1.0 | 1,940 | 5/15/2024 |
9.0.2 | 208 | 5/13/2024 |
9.0.0 | 10,915 | 3/13/2024 |
9.0.0-pre.4 | 72 | 4/19/2024 |
9.0.0-pre.3 | 61 | 3/21/2024 |
9.0.0-pre.2 | 62 | 3/13/2024 |
9.0.0-pre.1 | 70 | 3/7/2024 |
8.0.2-pre.2 | 78 | 2/21/2024 |
8.0.2-pre.1 | 55 | 2/19/2024 |
8.0.1 | 10,495 | 2/13/2024 |
8.0.1-pre.7 | 75 | 2/12/2024 |
8.0.1-pre.6 | 71 | 2/7/2024 |
8.0.1-pre.5 | 68 | 2/5/2024 |
8.0.1-pre.4 | 69 | 1/31/2024 |
8.0.1-pre.3 | 68 | 1/26/2024 |
8.0.1-pre.2 | 69 | 1/25/2024 |
8.0.1-pre.1 | 62 | 1/18/2024 |
8.0.0 | 845 | 1/17/2024 |
8.0.0-pre.45 | 62 | 1/17/2024 |
8.0.0-pre.44 | 64 | 1/16/2024 |
8.0.0-pre.43 | 62 | 1/16/2024 |
8.0.0-pre.42 | 808 | 1/10/2024 |
8.0.0-pre.41 | 295 | 1/2/2024 |
8.0.0-pre.40 | 166 | 12/27/2023 |
8.0.0-pre.39 | 73 | 12/21/2023 |
8.0.0-pre.38 | 415 | 12/6/2023 |
8.0.0-pre.37 | 134 | 12/6/2023 |
8.0.0-pre.36 | 137 | 12/3/2023 |
8.0.0-pre.35 | 100 | 11/28/2023 |
8.0.0-pre.34 | 90 | 11/24/2023 |
8.0.0-pre.33 | 72 | 11/24/2023 |
8.0.0-pre.32 | 70 | 11/23/2023 |
8.0.0-pre.31 | 75 | 11/23/2023 |
8.0.0-pre.30 | 76 | 11/23/2023 |
8.0.0-pre.29 | 479 | 11/11/2023 |
8.0.0-pre.28 | 88 | 11/8/2023 |
8.0.0-pre.27 | 578 | 10/23/2023 |
8.0.0-pre.26 | 111 | 10/19/2023 |
8.0.0-pre.25 | 78 | 10/18/2023 |
8.0.0-pre.24 | 96 | 10/13/2023 |
8.0.0-pre.23 | 80 | 10/13/2023 |
8.0.0-pre.22 | 75 | 10/13/2023 |
8.0.0-pre.21 | 82 | 10/12/2023 |
8.0.0-pre.20 | 80 | 10/11/2023 |
8.0.0-pre.19 | 81 | 10/9/2023 |
8.0.0-pre.18 | 75 | 10/9/2023 |
8.0.0-pre.17 | 74 | 10/7/2023 |
8.0.0-pre.16 | 106 | 10/6/2023 |
8.0.0-pre.15 | 73 | 10/6/2023 |
8.0.0-pre.14 | 73 | 10/5/2023 |
8.0.0-pre.13 | 72 | 10/5/2023 |
8.0.0-pre.12 | 75 | 10/4/2023 |
8.0.0-pre.11 | 76 | 10/3/2023 |
8.0.0-pre.10 | 78 | 10/3/2023 |
8.0.0-pre.9 | 74 | 10/3/2023 |
8.0.0-pre.8 | 74 | 10/2/2023 |
8.0.0-pre.7 | 74 | 10/2/2023 |
8.0.0-pre.6 | 76 | 9/29/2023 |
8.0.0-pre.5 | 72 | 9/28/2023 |
8.0.0-pre.4 | 72 | 9/28/2023 |
8.0.0-pre.3 | 71 | 9/27/2023 |
8.0.0-pre.2 | 61 | 9/26/2023 |
8.0.0-pre.1 | 71 | 9/22/2023 |
'# [8.0.0-pre.34](https://github.com/buehler/dotnet-operator-sdk/compare/v8.0.0-pre.33...v8.0.0-pre.34) (2023-11-24)
### Bug Fixes
* **cli:** readd c# support. ([7c76e54](https://github.com/buehler/dotnet-operator-sdk/commit/7c76e54dba7ddf76c066668c7720e1c60fec9517))
'