KubeOps.Operator 10.0.0-prerelease.3

This is a prerelease version of KubeOps.Operator.
There is a newer version of this package available.
See the version list below for details.
dotnet add package KubeOps.Operator --version 10.0.0-prerelease.3
                    
NuGet\Install-Package KubeOps.Operator -Version 10.0.0-prerelease.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KubeOps.Operator" Version="10.0.0-prerelease.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KubeOps.Operator" Version="10.0.0-prerelease.3" />
                    
Directory.Packages.props
<PackageReference Include="KubeOps.Operator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KubeOps.Operator --version 10.0.0-prerelease.3
                    
#r "nuget: KubeOps.Operator, 10.0.0-prerelease.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KubeOps.Operator@10.0.0-prerelease.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KubeOps.Operator&version=10.0.0-prerelease.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=KubeOps.Operator&version=10.0.0-prerelease.3&prerelease
                    
Install as a Cake Tool

KubeOps Operator

NuGet NuGet Pre-Release

The KubeOps.Operator package provides a framework for building Kubernetes operators in .NET. Built on top of the Kubernetes client libraries for .NET, it offers abstractions and utilities for implementing operators that manage custom resources in a Kubernetes cluster.

Getting Started

Install the package from NuGet:

dotnet add package KubeOps.Operator

After installation, you can create entities, controllers, finalizers, and other components to implement your operator.

All resources must be registered with the operator builder to be recognized by the SDK and used as operator resources. The KubeOps.Generator provides convenience methods to register all components at once.

You'll need to use the Generic Host to run your operator. For a plain operator without webhooks, ASP.NET is not required (unlike v7).

using KubeOps.Operator;
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 RegisterComponents function:

builder.Services
    .AddKubernetesOperator()
    .RegisterComponents();

Alternatively, you can register resources manually:

builder.Services
    .AddKubernetesOperator()
    .AddController<TestController, V1TestEntity>()
    .AddFinalizer<FirstFinalizer, V1TestEntity>("first")
    .AddFinalizer<SecondFinalizer, V1TestEntity>("second");

Entity

To create an entity, implement the IKubernetesObject<V1ObjectMeta> interface. The SDK provides convenience classes to help with initialization, status, and spec properties.

[KubernetesEntity(Group = "testing.dev", ApiVersion = "v1", Kind = "TestEntity")]
public sealed 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 reconciles a specific entity type. Implement controllers using the IEntityController<TEntity> interface. You can reconcile custom entities or other Kubernetes resources as long as they are registered with the operator. For guidance on reconciling external resources, refer to the documentation.

Example controller implementation:

using KubeOps.Abstractions.Reconciliation;
using KubeOps.Abstractions.Reconciliation.Controller;
using KubeOps.Abstractions.Rbac;
using KubeOps.KubernetesClient;
using Microsoft.Extensions.Logging;

[EntityRbac(typeof(V1TestEntity), Verbs = RbacVerb.All)]
public sealed class V1TestEntityController : IEntityController<V1TestEntity>
{
    private readonly IKubernetesClient _client;
    private readonly ILogger<V1TestEntityController> _logger;

    public V1TestEntityController(
        IKubernetesClient client,
        ILogger<V1TestEntityController> logger)
    {
        _client = client;
        _logger = logger;
    }

    public async Task<ReconciliationResult<V1TestEntity>> ReconcileAsync(V1TestEntity entity, CancellationToken cancellationToken)
    {
        _logger.LogInformation("Reconciling entity {Entity}.", entity);

        // Update status to indicate reconciliation in progress
        entity.Status.Status = "Reconciling";
        entity = await _client.UpdateStatus(entity);

        // Update status to indicate reconciliation complete
        entity.Status.Status = "Reconciled";
        await _client.UpdateStatus(entity);
        
        return ReconciliationResult<V1TestEntity>.Success(entity);
    }

    public Task<ReconciliationResult<V1TestEntity>> DeletedAsync(V1TestEntity entity, CancellationToken cancellationToken)
    {
        _logger.LogInformation("Entity {Entity} deleted.", entity);
        return Task.FromResult(ReconciliationResult<V1TestEntity>.Success(entity));
    }
}

This controller:

  1. Updates the entity's status to indicate reconciliation is in progress
  2. Updates the status again to indicate reconciliation is complete
  3. Implements the required DeletedAsync method for handling deletion events

CAUTION: Always use the returned values from modifying actions of the Kubernetes client. Failure to do so will result in "HTTP CONFLICT" errors due to 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 validate or transform values), use webhooks instead.

Finalizer

A finalizer is a mechanism for asynchronous cleanup in Kubernetes. Implement finalizers using the IEntityFinalizer<TEntity> interface.

KubeOps provides automatic finalizer attachment and detachment to ensure proper resource cleanup. If you need special handling this automation can be disabled by configuration. Finalizers then are attached using an EntityFinalizerAttacher and are called when the entity is marked for deletion.

using KubeOps.Abstractions.Reconciliation;
using KubeOps.Abstractions.Reconciliation.Finalizer;

public sealed class FinalizerOne : IEntityFinalizer<V1TestEntity>
{
    public Task<ReconciliationResult<V1TestEntity>> FinalizeAsync(V1TestEntity entity, CancellationToken cancellationToken)
    {
        // Implement cleanup logic here
        return Task.FromResult(ReconciliationResult<V1TestEntity>.Success(entity));
    }
}

NOTE: The controller's DeletedAsync method will be called after all finalizers are removed.

Documentation

For more information, visit the documentation.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
10.0.3-prerelease.1 31 12/10/2025
10.0.2 193 12/9/2025
10.0.2-prerelease.1 139 12/3/2025
10.0.1 1,151 12/2/2025
10.0.1-prerelease.1 126 11/27/2025
10.0.0 509 11/25/2025
10.0.0-prerelease.4 158 11/25/2025
10.0.0-prerelease.3 188 11/24/2025
10.0.0-prerelease.2 131 11/24/2025
10.0.0-prerelease.1 342 11/21/2025
9.11.10-prerelease.1 225 11/13/2025
9.11.9 3,874 11/11/2025
9.11.9-prerelease.1 102 11/7/2025
9.11.8 4,094 10/28/2025
9.11.8-prerelease.1 139 10/26/2025
9.11.7 2,107 10/15/2025
9.11.7-prerelease.2 131 10/15/2025
9.11.7-prerelease.1 133 10/14/2025
9.11.6 332 10/14/2025
9.11.6-prerelease.1 59 10/10/2025
9.11.5 612 10/7/2025
9.11.5-prerelease.2 129 10/5/2025
9.11.5-prerelease.1 132 10/1/2025
9.11.4 4,914 9/16/2025
9.11.4-prerelease.1 136 9/10/2025
9.11.3 965 9/9/2025
9.11.3-prerelease.1 108 9/7/2025
9.11.2 2,242 8/19/2025
9.11.2-prerelease.2 132 8/17/2025
9.11.2-prerelease.1 133 8/12/2025
9.11.1 3,492 7/29/2025
9.11.1-prerelease.3 140 7/27/2025
9.11.1-prerelease.2 471 7/24/2025
9.11.1-prerelease.1 524 7/22/2025
9.11.0 1,532 7/22/2025
9.11.0-prerelease.7 128 7/17/2025
9.11.0-prerelease.6 133 7/17/2025
9.11.0-prerelease.5 126 7/17/2025
9.11.0-prerelease.4 126 7/17/2025
9.11.0-prerelease.3 127 7/17/2025
9.11.0-prerelease.2 127 7/16/2025
9.11.0-prerelease.1 130 7/16/2025
9.10.0 2,891 7/3/2025
9.9.0 954 6/30/2025
9.8.2 1,348 6/20/2025
9.8.1 971 6/13/2025
9.8.0 886 6/10/2025
9.7.0 915 6/6/2025
9.6.0 13,609 5/23/2025
9.5.0 6,365 5/8/2025
9.4.1 9,348 4/29/2025
9.4.0 625 4/28/2025
9.3.0 6,848 3/26/2025
9.2.0 12,974 1/24/2025
9.1.5 40,957 9/10/2024
9.1.4 1,635 8/26/2024
9.1.3 19,487 6/28/2024
9.1.2 11,766 6/20/2024
9.1.1 5,836 5/22/2024
9.1.0 2,440 5/15/2024
9.0.2 821 5/13/2024
9.0.0 15,573 3/13/2024
9.0.0-pre.4 114 4/19/2024
9.0.0-pre.3 122 3/21/2024
9.0.0-pre.2 134 3/13/2024
9.0.0-pre.1 136 3/7/2024
8.0.2-pre.2 144 2/21/2024
8.0.2-pre.1 111 2/19/2024
8.0.1 11,398 2/13/2024
8.0.1-pre.7 142 2/12/2024
8.0.1-pre.6 125 2/7/2024
8.0.1-pre.5 122 2/5/2024
8.0.1-pre.4 117 1/31/2024
8.0.1-pre.3 139 1/26/2024
8.0.1-pre.2 130 1/25/2024
8.0.1-pre.1 124 1/18/2024
8.0.0 1,051 1/17/2024
8.0.0-pre.45 101 1/17/2024
8.0.0-pre.44 126 1/16/2024
8.0.0-pre.43 112 1/16/2024
8.0.0-pre.42 873 1/10/2024
8.0.0-pre.41 354 1/2/2024
8.0.0-pre.40 221 12/27/2023
8.0.0-pre.39 143 12/21/2023
8.0.0-pre.38 456 12/6/2023
8.0.0-pre.37 177 12/6/2023
8.0.0-pre.36 201 12/3/2023
8.0.0-pre.35 136 11/28/2023
8.0.0-pre.34 166 11/24/2023
8.0.0-pre.33 106 11/24/2023
8.0.0-pre.32 128 11/23/2023
8.0.0-pre.31 132 11/23/2023
8.0.0-pre.30 111 11/23/2023
8.0.0-pre.29 538 11/11/2023
8.0.0-pre.28 147 11/8/2023
8.0.0-pre.27 651 10/23/2023
8.0.0-pre.26 173 10/19/2023
8.0.0-pre.25 128 10/18/2023
8.0.0-pre.24 141 10/13/2023
8.0.0-pre.23 151 10/13/2023
8.0.0-pre.22 140 10/13/2023
8.0.0-pre.21 150 10/12/2023
8.0.0-pre.20 147 10/11/2023
8.0.0-pre.19 152 10/9/2023
8.0.0-pre.18 143 10/9/2023
8.0.0-pre.17 113 10/7/2023
8.0.0-pre.16 180 10/6/2023
8.0.0-pre.15 138 10/6/2023
8.0.0-pre.14 142 10/5/2023
8.0.0-pre.13 138 10/5/2023
8.0.0-pre.12 134 10/4/2023
8.0.0-pre.11 141 10/3/2023
8.0.0-pre.10 149 10/3/2023
8.0.0-pre.9 117 10/3/2023
8.0.0-pre.8 143 10/2/2023
8.0.0-pre.7 113 10/2/2023
8.0.0-pre.6 137 9/29/2023
8.0.0-pre.5 131 9/28/2023
8.0.0-pre.4 117 9/28/2023
8.0.0-pre.3 147 9/27/2023
8.0.0-pre.2 102 9/26/2023
8.0.0-pre.1 142 9/22/2023