https://github.com/miroslavrepka/killcatcher
Simple go module for detecting the pod deletion from Kubernetes cluster
https://github.com/miroslavrepka/killcatcher
go kubernetes kubernetes-pods termination-detection-algorithm
Last synced: 10 months ago
JSON representation
Simple go module for detecting the pod deletion from Kubernetes cluster
- Host: GitHub
- URL: https://github.com/miroslavrepka/killcatcher
- Owner: MiroslavRepka
- License: mit
- Created: 2022-09-17T10:28:03.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T11:57:39.000Z (about 3 years ago)
- Last Synced: 2025-02-05T23:19:35.006Z (12 months ago)
- Topics: go, kubernetes, kubernetes-pods, termination-detection-algorithm
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# killCatcher
[](https://goreportcard.com/report/github.com/MiroslavRepka/killCatcher)
[](https://opensource.org/licenses/MIT)
Simple go module for detecting the pod deletion from Kubernetes cluster
## How to use it
Integration of this go module is quite simple. Inside your `main`, define `killCatcher` instance, and call `Listen()` in separate goroutine. It is up to you how you will manage those goroutines.
In this example, we will use `errorGroup`.
```go
func main(){
kc := killCatcher.New(postSigterm)
var eg errgroup.Group
eg.Go(killCatcher.Listen)
eg.Go(yourApp)
if err := eg.Wait(); err != nil {
fmt.Printf("Got error in one of the goroutines : %v\n", err)
os.Exit(1)
}
os.Exit(0)
}
func postSigterm() error{
//logic to execute after SIGTERM
}
func yourApp() error {
//main logic of your app
}
```
Lastly, do not forget to define `terminationGracePeriodSeconds` in you manifest file. By default, its set to `30s`, however, this might not suit your needs. Example can be found [here](test/pod.yaml).