Documentation
¶
Overview ¶
Package drainbudget is the one reading of a process's two drain knobs, PRE_STOP_DELAY and SHUTDOWN_TIMEOUT: how a value is written, what zero and a negative value mean, and the defaults.
Two parties read those variables and must agree to the second: the server, which flips readiness, pauses PRE_STOP_DELAY and then shuts down bounded by SHUTDOWN_TIMEOUT; and forge's renderer, which derives the pod's terminationGracePeriodSeconds from the same two values (pkg/deploy). When they disagree the kubelet SIGKILLs a replica mid-drain, or holds a dead one for a budget nobody asked for. Each party used to carry its own parser, and they drifted: one read "-1s" (no pause) as malformed and fell back to the default. Both now call this package.
The rule:
- A value is a Go duration ("30s", "1m30s", "500ms", "-1s") or a bare count of seconds ("30", "-1"). Empty is unset. Anything else is an error.
- Zero, set or unset, is the default: 5s for PRE_STOP_DELAY, 30s for SHUTDOWN_TIMEOUT.
- Negative is none: a phase that takes no time. Never unbounded.
It has no dependencies beyond the standard library, so the renderer can import it without linking serverkit.
Index ¶
Constants ¶
const ( // EnvPreStopDelay is how long the process keeps serving after its // readiness flips to draining, so load balancers observe the failing // probe before anything stops. EnvPreStopDelay = "PRE_STOP_DELAY" // EnvShutdownTimeout bounds everything after the pre-stop pause. EnvShutdownTimeout = "SHUTDOWN_TIMEOUT" // DefaultPreStopDelay is what a zero or unset PRE_STOP_DELAY means. DefaultPreStopDelay = 5 * time.Second // DefaultShutdownTimeout is what a zero or unset SHUTDOWN_TIMEOUT means. DefaultShutdownTimeout = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Budget ¶
Budget is a process's two drain knobs as configured — before Effective applies the rule, so a zero still means "the default" and a negative still means "none". Its fields map one to one onto serverkit.Config's PreStopDelay and ShutdownTimeout.
func FromEnv ¶
FromEnv reads both knobs through getenv — os.Getenv in a main; a library never reads the environment itself. An unset variable is zero (the default). A malformed one is an error naming the variable: a server should refuse to boot rather than run a budget its pod's grace period was not derived from.