Added liveness probe
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 5m47s
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 5m47s
This commit is contained in:
parent
f0bf60c78a
commit
8b95757a4e
73
Cargo.lock
generated
73
Cargo.lock
generated
|
@ -173,6 +173,60 @@ version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de45108900e1f9b9242f7f2e254aa3e2c029c921c258fe9e6b4217eeebd54288"
|
||||||
|
dependencies = [
|
||||||
|
"axum-core",
|
||||||
|
"bytes",
|
||||||
|
"form_urlencoded",
|
||||||
|
"futures-util",
|
||||||
|
"http",
|
||||||
|
"http-body",
|
||||||
|
"http-body-util",
|
||||||
|
"hyper",
|
||||||
|
"hyper-util",
|
||||||
|
"itoa",
|
||||||
|
"matchit",
|
||||||
|
"memchr",
|
||||||
|
"mime",
|
||||||
|
"percent-encoding",
|
||||||
|
"pin-project-lite",
|
||||||
|
"rustversion",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_path_to_error",
|
||||||
|
"serde_urlencoded",
|
||||||
|
"sync_wrapper",
|
||||||
|
"tokio",
|
||||||
|
"tower",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum-core"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"http",
|
||||||
|
"http-body",
|
||||||
|
"http-body-util",
|
||||||
|
"mime",
|
||||||
|
"pin-project-lite",
|
||||||
|
"rustversion",
|
||||||
|
"sync_wrapper",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace"
|
name = "backtrace"
|
||||||
version = "0.3.71"
|
version = "0.3.71"
|
||||||
|
@ -1700,6 +1754,12 @@ dependencies = [
|
||||||
"regex-automata 0.1.10",
|
"regex-automata 0.1.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "matchit"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "md5"
|
name = "md5"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@ -2769,6 +2829,16 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_path_to_error"
|
||||||
|
version = "0.1.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_urlencoded"
|
name = "serde_urlencoded"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
|
@ -2862,6 +2932,7 @@ dependencies = [
|
||||||
name = "siranga"
|
name = "siranga"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"axum",
|
||||||
"bytes",
|
"bytes",
|
||||||
"clap",
|
"clap",
|
||||||
"clio",
|
"clio",
|
||||||
|
@ -3231,6 +3302,7 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3251,6 +3323,7 @@ version = "0.1.41"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"log",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tracing-attributes",
|
"tracing-attributes",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
|
|
|
@ -5,6 +5,7 @@ default-run = "siranga"
|
||||||
license = "AGPL-3.0-only"
|
license = "AGPL-3.0-only"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
axum = "0.8.3"
|
||||||
bytes = "1.10.1"
|
bytes = "1.10.1"
|
||||||
clap = { version = "4.5.35", features = ["derive"] }
|
clap = { version = "4.5.35", features = ["derive"] }
|
||||||
clio = { version = "0.3.5", features = ["clap-parse"] }
|
clio = { version = "0.3.5", features = ["clap-parse"] }
|
||||||
|
|
|
@ -35,6 +35,8 @@ spec:
|
||||||
containerPort: 2222
|
containerPort: 2222
|
||||||
- name: http
|
- name: http
|
||||||
containerPort: 3000
|
containerPort: 3000
|
||||||
|
- name: metrics
|
||||||
|
containerPort: 4000
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: credentials
|
- name: credentials
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
@ -59,6 +61,12 @@ spec:
|
||||||
value: /secrets/credentials/password
|
value: /secrets/credentials/password
|
||||||
- name: PRIVATE_KEY_FILE
|
- name: PRIVATE_KEY_FILE
|
||||||
value: /secrets/key/private.pem
|
value: /secrets/key/private.pem
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: metrics
|
||||||
|
initialDelaySeconds: 3
|
||||||
|
periodSeconds: 3
|
||||||
volumes:
|
volumes:
|
||||||
- name: credentials
|
- name: credentials
|
||||||
secret:
|
secret:
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -4,6 +4,8 @@ use std::net::SocketAddr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use axum::Router;
|
||||||
|
use axum::routing::get;
|
||||||
use color_eyre::eyre::Context;
|
use color_eyre::eyre::Context;
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
|
@ -54,6 +56,10 @@ async fn shutdown_task(token: CancellationToken) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn axum_graceful_shutdown(token: CancellationToken) {
|
||||||
|
token.cancelled().await;
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> color_eyre::Result<()> {
|
async fn main() -> color_eyre::Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
@ -85,12 +91,18 @@ async fn main() -> color_eyre::Result<()> {
|
||||||
russh::keys::PrivateKey::random(&mut OsRng, russh::keys::Algorithm::Ed25519)?
|
russh::keys::PrivateKey::random(&mut OsRng, russh::keys::Algorithm::Ed25519)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let http_port = std::env::var("HTTP_PORT")
|
|
||||||
.map(|port| port.parse().wrap_err_with(|| format!("HTTP_PORT={port}")))
|
|
||||||
.unwrap_or(Ok(3000))?;
|
|
||||||
let ssh_port = std::env::var("SSH_PORT")
|
let ssh_port = std::env::var("SSH_PORT")
|
||||||
.map(|port| port.parse().wrap_err_with(|| format!("SSH_PORT={port}")))
|
.map(|port| port.parse().wrap_err_with(|| format!("SSH_PORT={port}")))
|
||||||
.unwrap_or(Ok(2222))?;
|
.unwrap_or(Ok(2222))?;
|
||||||
|
let http_port = std::env::var("HTTP_PORT")
|
||||||
|
.map(|port| port.parse().wrap_err_with(|| format!("HTTP_PORT={port}")))
|
||||||
|
.unwrap_or(Ok(3000))?;
|
||||||
|
let metrics_port = std::env::var("METRICS_PORT")
|
||||||
|
.map(|port| {
|
||||||
|
port.parse()
|
||||||
|
.wrap_err_with(|| format!("METRICS_PORT={port}"))
|
||||||
|
})
|
||||||
|
.unwrap_or(Ok(4000))?;
|
||||||
|
|
||||||
let domain =
|
let domain =
|
||||||
std::env::var("TUNNEL_DOMAIN").unwrap_or_else(|_| format!("localhost:{http_port}"));
|
std::env::var("TUNNEL_DOMAIN").unwrap_or_else(|_| format!("localhost:{http_port}"));
|
||||||
|
@ -114,13 +126,24 @@ async fn main() -> color_eyre::Result<()> {
|
||||||
let http_task = service.serve(http_listener, token.clone());
|
let http_task = service.serve(http_listener, token.clone());
|
||||||
info!("HTTP is available on {http_addr}");
|
info!("HTTP is available on {http_addr}");
|
||||||
|
|
||||||
|
let metrics_app = Router::new().route("/health", get(async || "UP"));
|
||||||
|
let metrics_addr = SocketAddr::from(([0, 0, 0, 0], metrics_port));
|
||||||
|
let metrics_listener = TcpListener::bind(metrics_addr).await?;
|
||||||
|
let metrics = axum::serve(metrics_listener, metrics_app)
|
||||||
|
.with_graceful_shutdown(axum_graceful_shutdown(token.clone()));
|
||||||
|
info!("Metrics are available on {http_addr}");
|
||||||
|
|
||||||
select! {
|
select! {
|
||||||
_ = join!(ldap_handle, ssh_task, http_task) => {
|
_ = join!(ldap_handle, ssh_task, http_task, metrics.into_future()) => {
|
||||||
info!("Shutdown gracefully");
|
info!("Shutdown gracefully");
|
||||||
}
|
}
|
||||||
_ = shutdown_task(token.clone()) => {
|
_ = shutdown_task(token.clone()) => {
|
||||||
error!("Failed to shutdown gracefully");
|
error!("Failed to shutdown gracefully");
|
||||||
}
|
}
|
||||||
|
_ = tokio::time::sleep(std::time::Duration::from_secs(30)) => {
|
||||||
|
debug!("Simulating issue");
|
||||||
|
shutdown_task(token.clone()).await;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user