All Projects → ianlewis → controllerutil

ianlewis / controllerutil

Licence: Apache-2.0 license
Utilities for writing Kubernetes controllers & operators

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to controllerutil

Chowkidar
A kubernetes controller that watches/observes events & then takes configured actions – [✩Star] if you're using it!
Stars: ✭ 55 (+61.76%)
Mutual labels:  kubernetes-controller
mysql-operator
Asynchronous MySQL Replication on Kubernetes using Percona Server and Openark's Orchestrator.
Stars: ✭ 810 (+2282.35%)
Mutual labels:  kubernetes-controller
kubereplay
Seamless integration of goReplay and Kubernetes
Stars: ✭ 30 (-11.76%)
Mutual labels:  kubernetes-controller
vault-sidecar-injector
Kubernetes admission webhook for secure, seamless and dynamic handling of secrets in your applications
Stars: ✭ 55 (+61.76%)
Mutual labels:  kubernetes-controller
aws-vpn-controller
The AWS VPN Controller allows you to create and delete AWS VPNs and connect them to your VPCs using Kubernetes Custom Resource Definitions.
Stars: ✭ 26 (-23.53%)
Mutual labels:  kubernetes-controller
aws-cloud-map-mcs-controller-for-k8s
K8s controller implementing Multi-Cluster Services API based on AWS Cloud Map.
Stars: ✭ 61 (+79.41%)
Mutual labels:  kubernetes-controller
Strimzi Kafka Operator
Apache Kafka running on Kubernetes
Stars: ✭ 2,833 (+8232.35%)
Mutual labels:  kubernetes-controller
sentinel
Watch for changes in the status of Kubernetes resources and publish them to other systems for processing.
Stars: ✭ 15 (-55.88%)
Mutual labels:  kubernetes-controller
certificate-expiry-monitor-controller
Certificate Expiry Monitor Controller monitors the expiration of TLS certificates used in Ingress.
Stars: ✭ 114 (+235.29%)
Mutual labels:  kubernetes-controller
k8s-dt-node-labeller
Kubernetes controller for labelling a node with devicetree properties
Stars: ✭ 17 (-50%)
Mutual labels:  kubernetes-controller
kotary
Managing Kubernetes Quota with confidence
Stars: ✭ 85 (+150%)
Mutual labels:  kubernetes-controller
vegeta-controller
VegetaController is Kubernetes Custom Controller that allows distributed execution of tsenart/vegeta.
Stars: ✭ 23 (-32.35%)
Mutual labels:  kubernetes-controller
gotway
☸️ Cloud native API Gateway powered with in-redis cache
Stars: ✭ 71 (+108.82%)
Mutual labels:  kubernetes-controller
cf-k8s-networking
building a cloud foundry without gorouter....
Stars: ✭ 33 (-2.94%)
Mutual labels:  kubernetes-controller
cdap-operator
CDAP Kubernetes Operator
Stars: ✭ 17 (-50%)
Mutual labels:  kubernetes-controller
Skipper
An HTTP router and reverse proxy for service composition, including use cases like Kubernetes Ingress
Stars: ✭ 2,606 (+7564.71%)
Mutual labels:  kubernetes-controller
active-monitor
Provides deep monitoring and self-healing of Kubernetes clusters
Stars: ✭ 135 (+297.06%)
Mutual labels:  kubernetes-controller
upgrade-manager
Reliable, extensible rolling-upgrades of Autoscaling groups in Kubernetes
Stars: ✭ 132 (+288.24%)
Mutual labels:  kubernetes-controller
thundernetes
Thundernetes makes it easy to run your game servers on Kubernetes
Stars: ✭ 215 (+532.35%)
Mutual labels:  kubernetes-controller
ctrl
Tiny Kubernetes controller framework
Stars: ✭ 16 (-52.94%)
Mutual labels:  kubernetes-controller

Kubernetes Controller Utilities

Go Report Card

The github.com/ianlewis/controllerutil package provides a simple way to manage multiple Kubernetes controllers as part of a single process.

Project Status

Project status: alpha

controllerutil is still under active development and has not been extensively tested yet. Use at your own risk. Backward-compatibility is not supported for alpha releases.

Motivation

Kubernetes controllers are often run together as part of a single process but often it's unclear how to manage the lifecycle of each controller. Each controller also makes use of one or more "informers" which are used to watch the Kubernetes API for changes to objects and maintain a local cache per object type. Informers have their own lifecycle and need to managed as well.

This complexity, while powerful, often results in architectures that are error prone and don't handle edge cases well; particularly failure cases. The goal of this library is to provide an easy way for developers of controllers to take advantage of Go programming, logging, and Kubernetes API client best practices.

Installation

Install using

go get github.com/ianlewis/controllerutil

Architecture

controllerutil helps manage client-go data structures. Each controller application watches Kubernetes objects for changes via the Kubernetes API. Watches are done via data structures called "informers". Informer logic is combined with a local cache of objects in a data structure called a "shared index informer. Each shared index informer is shared across the process per API type. Maintaining a cache local to the application is done to lessen the load on the Kubernetes API server.

Each controller application can contain multiple control loops called "controllers". Shared index informers for the necessary types are passed to controllers in their constructor. Each controller is run in parallel with others in a goroutine.

controllerutil implements a ControllerManager which manages each controller and associated goroutine. Since most controller applications require all controllers to properly function, If any controller fails ControllerManager stops all controllers and terminates. It is assumed that the controller will be run with a supervisor such as the kubelet and will be restarted.

controllerutil also has a SharedInformers data structure which manages a list of informers that is unique per Kubernetes API type and manages the associated goroutines.

Usage

This example shows how to use the controllerutil package to implement a Kubernetes controller or operator application that makes use of Kubernetes custom resources. See the example directory for a full example.

Here we create a ControllerManager via the NewControllerManager function. Then controllers are registered via the Register method. Finally we call the Run method to start all the registered controllers.

func Example_customResourceDefinition() {
	// Initialize an in-cluster Kubernetes client
	config, _ := rest.InClusterConfig()
	client, _ := clientset.NewForConfig(config)

	// Create the client for the custom resource definition (CRD) "Foo"
	fooclient, err := fooclientset.NewForConfig(config)
	if err != nil {
		// handle error
	}

	// Create a new ControllerManager instance
	m := controllerutil.NewControllerManager("foo", client)

	// Register the foo controller.
	m.Register("foo", func(ctx *controller.Context) controller.Interface {
		return NewFooController(
			// ctx.Client is the same client passed to controllerutil.New
			ctx.Client,
			// fooclient is the CRD client instance
			fooclient,
			// ctx.SharedInformers manages lifecycle of all shared informers
			// InformerFor registers the informer for the given type if it hasn't been registered already.
			ctx.SharedInformers.InformerFor(
				&examplev1.Foo{},
				func() cache.SharedIndexInformer {
					return fooinformers.NewFooInformer(
						fooclient,
						metav1.NamespaceAll,
						12*time.Hour,
						cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
					)
				},
			),
			// ctx.Recorder is used for recording Kubernetes events.
			ctx.Recorder,
			// ctx.Logger is a convenient wrapper used for logging.
			ctx.Logger,
		)
	})

	if err := m.Run(context.Background()); err != nil {
		// handle error
	}
}

Logging

containerutil provides a logger object per controller which can optionally be used to log messages. Loggers are a wrapper around glog but provides easy creation of standard log.Logger objects. Each logger is given a prefix based on the controller name which allows for easier log viewing.

Disclaimers

This is not an official Google product.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].