GithubHelp home page GithubHelp logo

openclarity / simple-controller-runtime Goto Github PK

View Code? Open in Web Editor NEW
0.0 11.0 1.0 29 KB

A simple implementation similar to the Kubernetes controller runtime which can be used to create controllers for both kubernetes and non-kubernetes resources.

License: Apache License 2.0

Makefile 11.37% Go 88.63%

simple-controller-runtime's Introduction

Simple Controller Runtime

A simple implementation similar to the Kubernetes controller runtime which can be used to create controllers for both Kubernetes and non-Kubernetes resources.

Architecture

The library has 3 basic constructs:

Feeders/Detector

This is responsible for detecting resources that need to be reconciled from any API/datasource and pushes them into the work queue.

The library currently provides a simple Poller feeder which will poll a GetItems function on a configurable interval and push all returned items into the queue.

Custom feeders (for example one listening to an event stream) can be written as long as they can push into the Enqueuer interface implemented by the work queue.

Work Queue

This is a FIFO queue which keeps track of resources which need to be reconciled. It handles duplicate enqueues of resources already in the queue and keeps track of resources which are currently being processed to allow parallel reconciliation without race conditions.

It also provides an ability to enqueue/re-queue an item after a certain time interval, during this period the queue keeps track of the item so that additional enqueues (triggered by a feeder for example) do not supersede the requested time interval.

Reconciler

This is the control logic loop, it reads events from the Work queue and runs the reconcile function provided for each event.

The reconcile function provided should be idempotent and attempt to move the resource towards the desired state.

If an error occurs during reconciliation then it is logged by the reconciler framework and that iteration will be marked as completed by the framework and the item removed from the queue.

If during the reconciliation it is known that the item will need to be re-queued for further processing (without waiting for the feeder, or after a specific amount of time) then there is a RequeueAfter error that can be raised and the reconciler will re-queue the item.

It is safe to run multiple Reconcilers consuming off the same work queue. Items can only be in the queue once and items will not be marked as done and removed from the queue until the reconciler has finished with them; this ensures parallel reconcilers never end up reconciling the same item so there are no race conditions.

Example

A example implementation is available in the examples/ folder, which can be run like:

go run example.go

simple-controller-runtime's People

Contributors

tehsmash avatar dependabot[bot] avatar

Watchers

Reinhardt Quelle avatar Márk Sági-Kazár avatar Ed Warnicke avatar  avatar Gal Bashan avatar Krisztian Gacsal avatar Zsolt Kacsándi avatar Peter Balogh avatar  avatar András Jáky avatar Idan Frimark avatar

Forkers

zsoltkacsandi

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.