Skip to content

A template to quick-start with kubernetes controller/operator implementation.

License

Notifications You must be signed in to change notification settings

naeemrashid/k8s-controller-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k8s-controller-template

A template to quick-start with kubernetes controller/operator implementation or more precisely kubernetes watcher to watch for changes in resources and apply custom logic. Template does not introduces new CRDs(Custom Resource Definitions) but that is intentional, have a look at kubernetes sample-controller for refrences.

Specify type of resources to watch for

Below is a watch loop for changes in Deployment resources

deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc:    controller.Create,
		UpdateFunc: controller.Update,
		DeleteFunc: controller.Delete,
	})

Implement your custom logic Here

// ObjectCreated performs logic to create event.
func (c *Controller) ObjectCreated(key string) error {
	return nil
}

// ObjectUpdated performs logic to create event.
func (c *Controller) ObjectUpdated(key string) error {
	return nil
}

// ObjectDeleted performs logic to create event.
func (c *Controller) ObjectDeleted(key string) error {
	return nil
}

Build and Run

// vendor the project using
go get github.com/thenaeem/k8s-controller-template
// Build container
make container
// Deploy to Kuberentes as a single replica of Deployment.

About

A template to quick-start with kubernetes controller/operator implementation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published