Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gojekfarm/kubehandler
A framework for writing Kubernetes controllers
https://github.com/gojekfarm/kubehandler
Last synced: 19 days ago
JSON representation
A framework for writing Kubernetes controllers
- Host: GitHub
- URL: https://github.com/gojekfarm/kubehandler
- Owner: gojekfarm
- License: apache-2.0
- Created: 2018-04-13T11:05:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-05T04:27:49.000Z (over 2 years ago)
- Last Synced: 2024-04-13T21:06:12.030Z (7 months ago)
- Language: Go
- Size: 43 KB
- Stars: 29
- Watchers: 19
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kubehandler
An event dispatcher for Kubernetes controllers.
__Note: This is alpha software. Please use with caution.__
### Sample Controller
There is a sample controller available in `sample-controller/`. You can use
that as a starting point for building a new controller.### EventHandler
Kubehandler defines a Go interface, EventHandler. Any type that implements this
interface can be used to handle events.```
type EventHandler interface {
GetName() string
GetSynced() cache.InformerSynced
GetInformer() cache.SharedInformer
AddFunc(ctx context.Context, namespace, name string) error
UpdateFunc(ctx context.Context, namespace, name string) error
DeleteFunc(ctx context.Context, namespace, name string) error
}
```Each of the Add/Update/Delete Funcs receive a context and the namespace and the name of the
resource that has been modified (or created or deleted).
`kubehandler.DefaultHandler` implements a DefaultHandler that accepts all
events and does nothing. In order to make use of this behaviour, you can use
the bundled DefaultHandler by inheriting from it:```
type DeploymentsHandler struct {
kubehandler.DefaultHandler
}
```You will need an EventLoop to consume events. You can create one like so:
```
loop := kubehandler.NewEventLoop("workqueueName")
```You can then register the EventHandler with the EventLoop.
```
loop.Register(&DeploymentsHandler{
DefaultHandler: kubehandler.DefaultHandler{
Synced: deploymentsInformer.Informer().HasSynced,
Informer: deploymentsInformer.Informer(),
},
})```
Finally, run the EventLoop.
```
threadiness := 2
ctx := context.Background()loop.Run(ctx, threadiness)
```You may use the context passed in to `EventLoop.Run` to stop the EventLoop.
```
ctx, cancelFunc := context.WithCancel(context.Background())
loop.Run(ctx, threadiness)cancelFunc()
```## DefaultHandler
DefaultHandler provides implementations of EventHandler.GetName() string
Returns defaultHandler.NameGetSynced() cache.InformerSynced
Returns defaultHandler.SyncedGetInformer() cache.SharedInformer
Returns defaultHandler.InformerThe following functions are no-ops.
```
AddFunc(ctx context.Context, namespace, name string) error
UpdateFunc(ctx context.Context, namespace, name string) error
DeleteFunc(ctx context.Context, namespace, name string) error
```Note: The current module supports Kubernetes 1.22 and above.
Kubernetes 1.21 and lower compatible module can be found in branch v0.