From ae5b124c16e0a0676b01b21dfa30ce8d8efde916 Mon Sep 17 00:00:00 2001 From: Tamipes Date: Sat, 20 Jun 2026 23:15:53 +0200 Subject: [PATCH 1/2] feat: update `test-deployment.yaml` to use a long shutdown timer as well --- kube/test-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kube/test-deployment.yaml b/kube/test-deployment.yaml index 0d5089a..e5d17b4 100644 --- a/kube/test-deployment.yaml +++ b/kube/test-deployment.yaml @@ -15,7 +15,7 @@ spec: app: minecraft-ingress spec: serviceAccountName: minecraft-ingress - terminationGracePeriodSeconds: 5 + terminationGracePeriodSeconds: 28800 # This is 8 hours containers: - name: minecraft-ingress image: git.tami.moe/tamipes/minecraft-ingress:testing From eac1c5d8fae494530aa788ede4f3902a569d693f Mon Sep 17 00:00:00 2001 From: Tamipes Date: Mon, 22 Jun 2026 14:34:29 +0200 Subject: [PATCH 2/2] feat: shut down the kubernetes api watcher if it recieved `SIGTERM` --- src/kube_cache.rs | 27 +++++++++++++++++++-------- src/main.rs | 11 +++++++---- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/kube_cache.rs b/src/kube_cache.rs index c929128..bba747b 100644 --- a/src/kube_cache.rs +++ b/src/kube_cache.rs @@ -40,13 +40,16 @@ impl KubeCache { /// and if it is not possible returns a None. /// /// It also returns a JoinHandle which is tied to the api watcher - /// and if it returns that means that the kubecache is not responsive now. + /// and if that handle is joinable that means that `kubecache` is + /// not responsive after that point. (the server should be restarted) /// /// # Example: /// ```no_run /// let (kube_cache, api_task) = kube_cache::KubeCache::create().await.unwrap(); /// ``` - pub async fn create() -> Option<(KubeCache, JoinHandle<()>)> { + pub async fn create( + token: tokio_util::sync::CancellationToken, + ) -> Option<(KubeCache, JoinHandle<()>)> { let in_cluster = match std::env::var("KUBERNETES_SERVICE_HOST") { Ok(_) => true, Err(_) => false, @@ -64,10 +67,16 @@ impl KubeCache { let infinite_watch = dep_watcher_rf .applied_objects() .for_each(|_o| std::future::ready(())); - let _res = infinite_watch.await; - tracing::error!( - "deployments watcher ended; this should not happen; (program should exit now)" - ); + tokio::select! { + _ = infinite_watch => { + tracing::error!( + "deployments watcher ended; this should not happen; (program should exit now)" + ); + } + _ = token.cancelled() => { + tracing::info!("shut down kubernetes api watcher"); + } + } }); let srv_api: Api = Api::default_namespaced(client); @@ -208,8 +217,10 @@ impl MinecraftAPI for McApi { } impl McApi { - pub async fn create() -> Option<(Self, JoinHandle<()>)> { - let (kube_cache, kube_task) = KubeCache::create().await?; + pub async fn create( + token: tokio_util::sync::CancellationToken, + ) -> Option<(Self, JoinHandle<()>)> { + let (kube_cache, kube_task) = KubeCache::create(token).await?; Some(( Self { cache: kube_cache, diff --git a/src/main.rs b/src/main.rs index 0a5bf94..a7f4e6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,11 @@ async fn main() { let revision: &'static str = env!("COMMIT_HASH"); tracing::info!(revision); - let (api, api_task) = kube_cache::McApi::create().await.unwrap(); + let cancel_token = tokio_util::sync::CancellationToken::new(); + + let (api, api_task) = kube_cache::McApi::create(cancel_token.clone()) + .await + .unwrap(); tracing::info!("initialized kube api"); let config: Config = Default::default(); @@ -43,7 +47,6 @@ async fn main() { return; } }; - let cancel_token = tokio_util::sync::CancellationToken::new(); let mut conn_task = proxy::start_proxy(listener, api, config, cancel_token.clone()); @@ -54,8 +57,8 @@ async fn main() { _ = &mut conn_task => { tracing::error!("the connection handling tokio:spawn'ed task ran to completion, which should not happen!"); } - result = sigterm.recv() => { - tracing::info!(sigterm_signal = ?result,"SIGTERM received"); + _ = sigterm.recv() => { + tracing::info!("SIGTERM received"); cancel_token.cancel(); let res = conn_task.await; tracing::info!(api_task_result = ?res, "shutdown complete");