Skip to content

MiroslavRepka/killCatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

killCatcher

Go Report Card License

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.

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.

About

Simple go module for detecting the pod deletion from Kubernetes cluster

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published