GithubHelp home page GithubHelp logo

isabella232 / wrangler-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rancher/wrangler

0.0 0.0 0.0 8.74 MB

Write controllers like a boss

License: Apache License 2.0

Go 99.96% Makefile 0.04%

wrangler-1's Introduction

Wrangler [BETA - Lacks full documentation]

Framework for wrapping clients, informers, listers into a simple usable controller pattern that promotes some good practices.

More documentation to follow but if you want to see what it looks like to write a controller with this framework refer to main.go and controller.go in the sample.

How it works

Most people writing controllers are a bit lost when they go to write a controller as they find that there is nothing in Kubernetes that is like type Controller interface where you can just do NewController. Instead a controller is really just a pattern of how you use the generated clientsets, informers, and listers combined with some custom event handlers and a workqueue.

Wrangler providers a code generator that will generate the clientset, informers, listers and additionally generate a controller per type. The interface to the controller looks as follows

To use the controller all one needs to do is register simple OnChange handlers. Also in the interface is access to the client and caches in a simple flat API. refer to main.go and controller.go in the sample project for more complete usage.

type FooController interface {
	FooClient

	OnChange(ctx context.Context, name string, sync FooHandler)
	OnRemove(ctx context.Context, name string, sync FooHandler)
	Enqueue(namespace, name string)

	Cache() FooCache

	Informer() cache.SharedIndexInformer
	GroupVersionKind() schema.GroupVersionKind

	AddGenericHandler(ctx context.Context, name string, handler generic.Handler)
	AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler)
	Updater() generic.Updater
}

type FooClient interface {
	Create(*v1alpha1.Foo) (*v1alpha1.Foo, error)
	Update(*v1alpha1.Foo) (*v1alpha1.Foo, error)
	UpdateStatus(*v1alpha1.Foo) (*v1alpha1.Foo, error)
	Delete(namespace, name string, options *metav1.DeleteOptions) error
	Get(namespace, name string, options metav1.GetOptions) (*v1alpha1.Foo, error)
	List(namespace string, opts metav1.ListOptions) (*v1alpha1.FooList, error)
	Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
	Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Foo, err error)
}

type FooCache interface {
	Get(namespace, name string) (*v1alpha1.Foo, error)
	List(namespace string, selector labels.Selector) ([]*v1alpha1.Foo, error)

	AddIndexer(indexName string, indexer FooIndexer)
	GetByIndex(indexName, key string) ([]*v1alpha1.Foo, error)
}

type FooIndexer func(obj *v1alpha1.Foo) ([]string, error)

wrangler-1's People

Contributors

daxmc99 avatar dramich avatar dweomer avatar ekristen avatar guangbochen avatar ibuildthecloud avatar kinarashah avatar luthermonson avatar matlec avatar rmweir 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.