killCatcher

package module
v0.0.0-...-c53e4f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2023 License: MIT Imports: 4 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(f func() error) *killCatcher

New returns new killCatcher with provided function which will be executed after SIGTERM

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL