https://github.com/naeemrashid/k8s-controller-template
A template to quick-start with kubernetes controller/operator implementation.
https://github.com/naeemrashid/k8s-controller-template
k8s-controller kubernetes-controller kubernetes-operator
Last synced: 8 months ago
JSON representation
A template to quick-start with kubernetes controller/operator implementation.
- Host: GitHub
- URL: https://github.com/naeemrashid/k8s-controller-template
- Owner: naeemrashid
- License: mit
- Created: 2019-04-17T10:39:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-20T10:31:03.000Z (about 7 years ago)
- Last Synced: 2025-01-13T01:47:43.958Z (over 1 year ago)
- Topics: k8s-controller, kubernetes-controller, kubernetes-operator
- Language: Go
- Size: 3.49 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/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.
```