swarm-controller: an opt-in plain /healthz and /readyz listener a kubelet can probe
This commit is contained in:
parent
c78d73ccd1
commit
ffbd2f4dea
1 changed files with 147 additions and 50 deletions
|
|
@ -110,8 +110,7 @@ use startup::{
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
hive_log::init();
|
||||
let stop = install_process_hooks();
|
||||
let (stop, health) = start_process().await?;
|
||||
|
||||
let path = socket_path();
|
||||
|
||||
|
|
@ -269,15 +268,7 @@ async fn main() -> Result<()> {
|
|||
reviews: Arc::default(),
|
||||
alerts: alerts::from_env(),
|
||||
};
|
||||
serve(listener, state, stop).await
|
||||
}
|
||||
|
||||
/// The TLS provider, and the stop signal. The signal is installed first thing,
|
||||
/// so a stop that arrives while the startup reads wait on a store that is down
|
||||
/// ends them instead of being ignored until `serve`.
|
||||
fn install_process_hooks() -> swarm_secret_client::Shutdown {
|
||||
swarm_secret_client::install_crypto_provider();
|
||||
swarm_secret_client::shutdown_signal()
|
||||
serve(listener, state, stop, health).await
|
||||
}
|
||||
|
||||
/// The value a startup step produced, or exit 0 when the stop signal ended the
|
||||
|
|
@ -286,6 +277,32 @@ fn exit_if_stopped<T>(started: Option<T>) -> T {
|
|||
started.unwrap_or_else(|| std::process::exit(0))
|
||||
}
|
||||
|
||||
/// The environment variable that names the plain probe listener's address.
|
||||
const HEALTH_ADDR_VAR: &str = "SWARM_CONTROLLER_HEALTH_ADDR";
|
||||
|
||||
/// What `main` sets up before anything else: logging, the TLS provider, the
|
||||
/// stop signal (installed first thing, so a stop that arrives while the startup
|
||||
/// reads wait on a store that is down ends them instead of being ignored until
|
||||
/// `serve`), and the opt-in `/healthz` and `/readyz` listener on the address
|
||||
/// [`HEALTH_ADDR_VAR`] names, which a kubelet can reach where the socket's
|
||||
/// `/readyz` is out of its way. Nothing binds when the variable is unset. The
|
||||
/// controller is a server with no loop of its own to beat, so the beat comes
|
||||
/// from a task on its runtime. `/readyz` stays not ready until [`serve`] sets
|
||||
/// its condition.
|
||||
async fn start_process() -> Result<(
|
||||
swarm_secret_client::Shutdown,
|
||||
swarm_secret_client::health::Health,
|
||||
)> {
|
||||
hive_log::init();
|
||||
swarm_secret_client::install_crypto_provider();
|
||||
let stop = swarm_secret_client::shutdown_signal();
|
||||
let health = swarm_secret_client::health::Health::from_env(HEALTH_ADDR_VAR, stop.clone())
|
||||
.await
|
||||
.context("starting the health listener")?;
|
||||
health.beat_on_runtime();
|
||||
Ok((stop, health))
|
||||
}
|
||||
|
||||
/// Registers the `bao.client_cert.*` gauges for the controller's own store
|
||||
/// certificate (`controller.pem`) on the jobq exporter, the one provider built
|
||||
/// at startup rather than on first use. Nothing when no exporter is configured.
|
||||
|
|
@ -302,13 +319,15 @@ fn register_cert_gauges(provider: Option<&opentelemetry_sdk::metrics::SdkMeterPr
|
|||
/// Start taking the queued review requests and answering the notification
|
||||
/// router's, then serve `state` on `listener` until `stop` resolves. The
|
||||
/// requests in hand finish for at most the drain; the review queue takes no
|
||||
/// request after `stop`.
|
||||
/// request after `stop`. `health` answers `/readyz` as the socket's does.
|
||||
async fn serve(
|
||||
listener: tokio::net::UnixListener,
|
||||
state: AppState,
|
||||
stop: impl Future<Output = ()> + Clone + Send + 'static,
|
||||
health: swarm_secret_client::health::Health,
|
||||
) -> Result<()> {
|
||||
routes::watch_store();
|
||||
let store = routes::watch_store();
|
||||
health.ready_when(routes::probe_condition(state.status.clone(), store));
|
||||
review_classifier::review::spawn_queue(&state, stop.clone());
|
||||
request_reviewer::spawn(&state);
|
||||
let serving = axum::serve(listener, build_app(state)).with_graceful_shutdown(stop.clone());
|
||||
|
|
|
|||
Loading…
Reference in a new issue