Giter Club home page Giter Club logo

kubecontroller-csharp's Introduction

Kubernetes Controllers for CRDs in C#

What is this?

This is a sample C# library for creating lightweight controllers for Kubernetes CRDs, using the Kubernetes C# client.

It is intended to show you how to get started writing your own controller for CRDs in C#, and it is not suited for production purposes.

Using this library

Considering a custom resource definition that can be found in KubeController.Sample/deploy/crd.yaml, building the C# object is done by creating an instance of the CustomResource generic class which mimics the structure of your CRD, and passing a handler function to be executed whenever an event is fired:

    var crd = new CustomResourceDefinition()
    {
        ApiVersion = "engineerd.dev/v1alpha1",
        PluralName = "examples",
        Kind = "Example",
        Namespace = "kubecontroller"
    };

    var controller = new Controller<ExampleCRD>(
        new Kubernetes(KubernetesClientConfiguration.BuildConfigFromConfigFile()),
        crd,
        (WatchEventType eventType, ExampleCRD example) =>
            Console.WriteLine("Event type: {0} for {1}", eventType, example.Metadata.Name));

    var cts = new CancellationTokenSource();
    await controller.StartAsync(cts.Token).ConfigureAwait(false);

Building from source

Prerequisites:

  • a Kubernetes cluster
  • .NET Core 2.2
  • VS Code (optionally, for debugging)

To run the sample, you first need to deploy the CRD (the sample uses the kubecontroller namespace), then start the console application:

$ kubectl create -f KubeController.Sample/deploy/crd.yaml
$ dotnet run KubeController.Sample/

At this point, you can start operating on Example objects in your namespace, and the handler will get executed.

kubecontroller-csharp's People

Contributors

radu-matei avatar

Watchers

 avatar  avatar

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.