From b5f9c5e81cbc291db30a83ee662eea46fbd329a7 Mon Sep 17 00:00:00 2001 From: Tamipes Date: Wed, 3 Jun 2026 13:23:37 +0200 Subject: [PATCH] fix: could not initilaize `kube-rs` inside cluster, should infer config now --- src/kube_cache.rs | 9 ++++----- src/main.rs | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/kube_cache.rs b/src/kube_cache.rs index c8be2e5..ea76a90 100644 --- a/src/kube_cache.rs +++ b/src/kube_cache.rs @@ -29,9 +29,8 @@ pub struct KubeCache { impl KubeCache { /// This initializes the creation of a "kubernetes client" /// and if it is not possible returns a None. - pub fn create() -> Option { - let kubeconfig = kube::config::Kubeconfig::read().unwrap(); - let client = Client::try_from(kubeconfig).unwrap(); + pub async fn create() -> Option { + let client = Client::try_default().await.unwrap(); let deployments: Api = Api::default_namespaced(client.clone()); let services: Api = Api::default_namespaced(client); @@ -209,9 +208,9 @@ impl MinecraftAPI for McApi { } impl McApi { - pub fn create() -> Option { + pub async fn create() -> Option { Some(Self { - cache: KubeCache::create()?, + cache: KubeCache::create().await?, map: Arc::new(tokio::sync::Mutex::new(HashMap::new())), }) } diff --git a/src/main.rs b/src/main.rs index 80c5a3c..044cbc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ async fn main() { let revision: &'static str = env!("COMMIT_HASH"); tracing::info!(revision); - let api = kube_cache::McApi::create().unwrap(); + let api = kube_cache::McApi::create().await.unwrap(); tracing::info!("initialized kube api"); let config: Config = Default::default();