https://github.com/opslevel/opslevel-k8s-controller
A utility library for easily making and running k8s controllers
https://github.com/opslevel/opslevel-k8s-controller
Last synced: over 1 year ago
JSON representation
A utility library for easily making and running k8s controllers
- Host: GitHub
- URL: https://github.com/opslevel/opslevel-k8s-controller
- Owner: OpsLevel
- License: mit
- Created: 2023-11-01T18:11:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-17T20:43:46.000Z (over 1 year ago)
- Last Synced: 2025-02-17T21:32:41.421Z (over 1 year ago)
- Language: Go
- Size: 155 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://app.opslevel.com/services/opslevel-k8s-controller/maturity-report)
# opslevel-k8s-controller
A utility library for easily making and running k8s controllers
# Installation
```bash
go get github.com/opslevel/opslevel-k8s-controller/v2024
```
Then to create a k8s controller you can simply do
```go
selector := opslevel_k8s_controller.K8SSelector{
ApiVersion: "apps/v1",
Kind: "Deployment",
Excludes: []string{`.metadata.namespace == "kube-system"`}
}
resync := time.Hour*24
batch := 500
runOnce := false
controller, err := opslevel_k8s_controller.NewK8SController(selector, resync, batch, runOnce)
if err != nil {
//... Handle error ...
}
callback := func(items []interface{}) {
for _, item := range items {
// ... Process K8S Resource ...
}
}
controller.OnAdd = callback
controller.OnUpdate = callback
controller.Start()
```
Because of the way the selector works you can easily target any k8s resource in your cluster and you have the power of JQ
to exclude resources that might match the expression.