-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement discovering mr_persistence in mr_server
- Loading branch information
Showing
5 changed files
with
44 additions
and
86 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use bevy::log; | ||
use k8s_openapi::api::core::v1::Pod; | ||
use kube::{api::ListParams, Api, Client}; | ||
use reqwest::Url; | ||
|
||
pub async fn discover_persistence() -> Option<Url> { | ||
let client = Client::try_default().await.ok()?; | ||
log::info!("Kubernetes environment detected, trying to fetch mr-persistence pods..."); | ||
|
||
let pods: Api<Pod> = Api::namespaced(client, "default"); | ||
let lp = ListParams::default() | ||
.labels("app=muddle-run,service=mr-persistence") | ||
.timeout(0); | ||
let pods_list = pods | ||
.list(&lp) | ||
.await | ||
.map_err(|err| { | ||
log::warn!("Failed to fetch kubernetes pods: {:?}", err); | ||
err | ||
}) | ||
.ok()?; | ||
|
||
let pod_ip = pods_list.items.first()?.status.as_ref()?.pod_ip.as_ref()?; | ||
let persistence_url = format!("http://{}:8083", pod_ip).parse().unwrap(); | ||
log::info!("Using \"{}\" as MUDDLE_PERSISTENCE_URL", persistence_url); | ||
|
||
Some(persistence_url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters