probez

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package probez provides a simple http server that implements Kubernetes readiness probes (e.g. /livez and /readyz) that can be embedded in containers with long running processes or added to gin services to ensure that they can control how Kubernetes views their service state.

Index

Constants

View Source
const (
	Healthz = "/healthz"
	Livez   = "/livez"
	Readyz  = "/readyz"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

The Probe Handler manages the health and readiness states of a container. When it is first created, it starts in a healthy, but not ready state. Users can mark the probe server as healthy, unhealthy, ready, or not ready, changing how it responds to HTTP Get requests at the /livez and /readyz endpoints respectively.

Users should either instantiate a new probez.Server and serve it on a bind address or they should configure a probez.Handler to use an http server or a gin router for serving requests. When the the service is ready, they should mark the probez.Handler as ready, and when it is shutting down, the server should be marked as not ready and unhealthy.

func New

func New() *Handler

New returns a probez.Handler that is healthy but not ready.

func (*Handler) Healthy

func (h *Handler) Healthy()

Healthy sets the probe server to healthy so that it responds 204 No Content to liveness probes at the /livez endpoint.

func (*Handler) Healthz

func (h *Handler) Healthz(w http.ResponseWriter, _ *http.Request)

Healthz implements the kubernetes liveness check and responds to /healthz and /livez

func (*Handler) IsHealthy

func (h *Handler) IsHealthy() bool

IsHealthy returns if the Handler is healthy or not

func (*Handler) IsReady

func (h *Handler) IsReady() bool

IsReady returns if the Handler is ready or not

func (*Handler) Mux

func (h *Handler) Mux(mux *http.ServeMux)

Mux adds the server's routes to the specified ServeMux.

func (*Handler) NotHealthy

func (h *Handler) NotHealthy()

NotHealthy sets the probe server to unhealthy so that it responds 503 Unavailable to liveness probes at the /livez endpoint.

func (*Handler) NotReady

func (h *Handler) NotReady()

NotReady sets the probe server state to not ready so that it responds 503 Unavailable to readiness probes at the /readyz endpoint.

func (*Handler) Ready

func (h *Handler) Ready()

Ready sets the probe server state to ready so that it responds 204 No Content to readiness probes at the /readyz endpoint. This operation is thread-safe.

func (*Handler) Readyz

func (h *Handler) Readyz(w http.ResponseWriter, _ *http.Request)

Readyz implements the kubernetes readiness check and responds to /readyz requests.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

func (*Handler) Use

func (h *Handler) Use(router *gin.Engine)

Use adds the server's routes to the specified Gin router.

type Probe

type Probe interface {
	Live(ctx context.Context) (bool, int, error)
	Ready(ctx context.Context) (bool, int, error)
	Healthy(ctx context.Context) (bool, int, error)
}

func NewProbe

func NewProbe(endpoint string) (_ Probe, err error)

type Server

type Server struct {
	Handler
	// contains filtered or unexported fields
}

Server is a quick way to get a probez.Handler service up and running, particularly for containers that do not necessarily serve HTTP requests.

func NewServer

func NewServer() *Server

New returns a probez.Server that is healthy but not ready.

func (*Server) Serve

func (s *Server) Serve(addr string) (err error)

Serve probe requests on the specified port, handling the /livez and /readyz endpoints according to the state of the server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) (err error)

Shutdown the http server and stop responding to probe requests.

func (*Server) URL

func (s *Server) URL() string

Directories

Path Synopsis
grpc
v1

Jump to

Keyboard shortcuts

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