Pass the kubernetes client as state.
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -1,4 +1,5 @@
|
||||
#![forbid(unsafe_code)]
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use axum::http::StatusCode;
|
||||
@@ -43,14 +44,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.await
|
||||
.expect("Set KUBECONFIG to a valid kubernetes config.");
|
||||
|
||||
let jobs: Api<PipelineRun> = Api::namespaced(kubernetes_client, "lighthouse");
|
||||
// let jobs: Api<PipelineRun> = Api::namespaced(kubernetes_client, "lighthouse");
|
||||
// let jobs: Api<PipelineRun> = Api::default_namespaced(kubernetes_client);
|
||||
tracing::info!("Using crd: {}", serde_json::to_string(&PipelineRun::crd())?);
|
||||
// tracing::info!("Using crd: {}", serde_json::to_string(&PipelineRun::crd())?);
|
||||
|
||||
let test_run: PipelineRun = serde_json::from_str(EXAMPLE_PIPELINE_RUN)?;
|
||||
// let test_run: PipelineRun = serde_json::from_str(EXAMPLE_PIPELINE_RUN)?;
|
||||
|
||||
let pp = PostParams::default();
|
||||
let created_run = jobs.create(&pp, &test_run).await?;
|
||||
// let pp = PostParams::default();
|
||||
// let created_run = jobs.create(&pp, &test_run).await?;
|
||||
|
||||
let app = Router::new()
|
||||
.route("/hook", post(hook))
|
||||
@@ -60,7 +61,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
TraceLayer::new_for_http(),
|
||||
// Add a timeout layer so graceful shutdown can't wait forever.
|
||||
TimeoutLayer::new(Duration::from_secs(600)),
|
||||
));
|
||||
))
|
||||
.with_state(AppState { kubernetes_client });
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:9988").await?;
|
||||
tracing::info!("listening on {}", listener.local_addr().unwrap());
|
||||
@@ -70,6 +72,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState {
|
||||
kubernetes_client: Client,
|
||||
}
|
||||
|
||||
async fn shutdown_signal() {
|
||||
let ctrl_c = async {
|
||||
signal::ctrl_c()
|
||||
|
||||
Reference in New Issue
Block a user