An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          



License


Made With Go


Release


Issues


Contributors


Activity


CodeCov


Dependabot


Go Reference

[![Overall](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fapp.opslevel.com%2Fapi%2Fservice_level%2FDEmrX2bjoPualtC4Pri1YvjydDrza6V1V5srMvcZNbQ)](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.