Compare commits
No commits in common. "eac1c5d8fae494530aa788ede4f3902a569d693f" and "7815e5f0d785d6d2e3ed44d3f58e7da1350a53a0" have entirely different histories.
eac1c5d8fa
...
7815e5f0d7
3 changed files with 13 additions and 27 deletions
|
|
@ -15,7 +15,7 @@ spec:
|
||||||
app: minecraft-ingress
|
app: minecraft-ingress
|
||||||
spec:
|
spec:
|
||||||
serviceAccountName: minecraft-ingress
|
serviceAccountName: minecraft-ingress
|
||||||
terminationGracePeriodSeconds: 28800 # This is 8 hours
|
terminationGracePeriodSeconds: 5
|
||||||
containers:
|
containers:
|
||||||
- name: minecraft-ingress
|
- name: minecraft-ingress
|
||||||
image: git.tami.moe/tamipes/minecraft-ingress:testing
|
image: git.tami.moe/tamipes/minecraft-ingress:testing
|
||||||
|
|
|
||||||
|
|
@ -40,16 +40,13 @@ impl KubeCache {
|
||||||
/// and if it is not possible returns a None.
|
/// and if it is not possible returns a None.
|
||||||
///
|
///
|
||||||
/// It also returns a JoinHandle which is tied to the api watcher
|
/// It also returns a JoinHandle which is tied to the api watcher
|
||||||
/// and if that handle is joinable that means that `kubecache` is
|
/// and if it returns that means that the kubecache is not responsive now.
|
||||||
/// not responsive after that point. (the server should be restarted)
|
|
||||||
///
|
///
|
||||||
/// # Example:
|
/// # Example:
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// let (kube_cache, api_task) = kube_cache::KubeCache::create().await.unwrap();
|
/// let (kube_cache, api_task) = kube_cache::KubeCache::create().await.unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn create(
|
pub async fn create() -> Option<(KubeCache, JoinHandle<()>)> {
|
||||||
token: tokio_util::sync::CancellationToken,
|
|
||||||
) -> Option<(KubeCache, JoinHandle<()>)> {
|
|
||||||
let in_cluster = match std::env::var("KUBERNETES_SERVICE_HOST") {
|
let in_cluster = match std::env::var("KUBERNETES_SERVICE_HOST") {
|
||||||
Ok(_) => true,
|
Ok(_) => true,
|
||||||
Err(_) => false,
|
Err(_) => false,
|
||||||
|
|
@ -67,16 +64,10 @@ impl KubeCache {
|
||||||
let infinite_watch = dep_watcher_rf
|
let infinite_watch = dep_watcher_rf
|
||||||
.applied_objects()
|
.applied_objects()
|
||||||
.for_each(|_o| std::future::ready(()));
|
.for_each(|_o| std::future::ready(()));
|
||||||
tokio::select! {
|
let _res = infinite_watch.await;
|
||||||
_ = infinite_watch => {
|
tracing::error!(
|
||||||
tracing::error!(
|
"deployments watcher ended; this should not happen; (program should exit now)"
|
||||||
"deployments watcher ended; this should not happen; (program should exit now)"
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
_ = token.cancelled() => {
|
|
||||||
tracing::info!("shut down kubernetes api watcher");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let srv_api: Api<Service> = Api::default_namespaced(client);
|
let srv_api: Api<Service> = Api::default_namespaced(client);
|
||||||
|
|
@ -217,10 +208,8 @@ impl MinecraftAPI<Server> for McApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McApi {
|
impl McApi {
|
||||||
pub async fn create(
|
pub async fn create() -> Option<(Self, JoinHandle<()>)> {
|
||||||
token: tokio_util::sync::CancellationToken,
|
let (kube_cache, kube_task) = KubeCache::create().await?;
|
||||||
) -> Option<(Self, JoinHandle<()>)> {
|
|
||||||
let (kube_cache, kube_task) = KubeCache::create(token).await?;
|
|
||||||
Some((
|
Some((
|
||||||
Self {
|
Self {
|
||||||
cache: kube_cache,
|
cache: kube_cache,
|
||||||
|
|
|
||||||
11
src/main.rs
11
src/main.rs
|
|
@ -27,11 +27,7 @@ async fn main() {
|
||||||
let revision: &'static str = env!("COMMIT_HASH");
|
let revision: &'static str = env!("COMMIT_HASH");
|
||||||
tracing::info!(revision);
|
tracing::info!(revision);
|
||||||
|
|
||||||
let cancel_token = tokio_util::sync::CancellationToken::new();
|
let (api, api_task) = kube_cache::McApi::create().await.unwrap();
|
||||||
|
|
||||||
let (api, api_task) = kube_cache::McApi::create(cancel_token.clone())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
tracing::info!("initialized kube api");
|
tracing::info!("initialized kube api");
|
||||||
|
|
||||||
let config: Config = Default::default();
|
let config: Config = Default::default();
|
||||||
|
|
@ -47,6 +43,7 @@ async fn main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let cancel_token = tokio_util::sync::CancellationToken::new();
|
||||||
|
|
||||||
let mut conn_task = proxy::start_proxy(listener, api, config, cancel_token.clone());
|
let mut conn_task = proxy::start_proxy(listener, api, config, cancel_token.clone());
|
||||||
|
|
||||||
|
|
@ -57,8 +54,8 @@ async fn main() {
|
||||||
_ = &mut conn_task => {
|
_ = &mut conn_task => {
|
||||||
tracing::error!("the connection handling tokio:spawn'ed task ran to completion, which should not happen!");
|
tracing::error!("the connection handling tokio:spawn'ed task ran to completion, which should not happen!");
|
||||||
}
|
}
|
||||||
_ = sigterm.recv() => {
|
result = sigterm.recv() => {
|
||||||
tracing::info!("SIGTERM received");
|
tracing::info!(sigterm_signal = ?result,"SIGTERM received");
|
||||||
cancel_token.cancel();
|
cancel_token.cancel();
|
||||||
let res = conn_task.await;
|
let res = conn_task.await;
|
||||||
tracing::info!(api_task_result = ?res, "shutdown complete");
|
tracing::info!(api_task_result = ?res, "shutdown complete");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue