util

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLeaderElect                 = true
	DefaultLeaderElectionNamespace     = "kube-system"
	DefaultLeaderElectionLeaseDuration = 60 * time.Second
	DefaultLeaderElectionRenewDeadline = 40 * time.Second
	DefaultLeaderElectionRetryPeriod   = 15 * time.Second

	DefaultEnableProfiling = false
	DefaultProfilerAddr    = "localhost:6060"
)

Variables

This section is empty.

Functions

func ContextWithStopCh

func ContextWithStopCh(ctx context.Context, stopCh <-chan struct{}) context.Context

ContextWithStopCh will wrap a context with a stop channel. When the provided stopCh closes, the cancel() will be called on the context. This provides a convenient way to represent a stop channel as a context.

func SetExitCode

func SetExitCode(err error)

SetExitCode sets the exit code to 1 if the error is not a context.Canceled error.

func SetupExitHandler

func SetupExitHandler(exitBehavior ExitBehavior) (<-chan struct{}, func())

SetupExitHandler: A stop channel is returned which is closed on receiving a shutdown signal (SIGTERM or SIGINT). If a second signal is caught, the program is terminated directly with exit code 130. SetupExitHandler also returns an exit function, this exit function calls os.Exit(...) if there is a exit code in the errorExitCodeChannel. The errorExitCodeChannel receives exit codes when SetExitCode is called or when a shutdown signal is received (only if exitBehavior is AlwaysErrCode).

Types

type ExitBehavior

type ExitBehavior int

ExitBehavior controls how the program should be terminated in response to a shutdown signal.

const (
	// AlwaysErrCode indicates the exit code of the program should always be nonzero
	// and should correspond to the numeric value of the signal that was received.
	AlwaysErrCode ExitBehavior = iota

	// GracefulShutdown treats a shutdown signal as a request to exit gracefully, terminating
	// goroutines and returning an exit code of 0 if there are no errors during shutdown.
	GracefulShutdown ExitBehavior = iota
)

Jump to

Keyboard shortcuts

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