Skip to content

Commit

Permalink
Wire up watcher to the pod template service
Browse files Browse the repository at this point in the history
  • Loading branch information
film42 committed Dec 12, 2023
1 parent a9b63b8 commit 3004e35
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 30 deletions.
180 changes: 161 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docbot-controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ serde = "1"
serde_yaml = "0.8"
tokio = { version = "1.15.0", features = ["full"] }
sha2 = "0.10"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

[build-dependencies]
docbot-crd = { path = "../docbot-crd" }
Expand Down
29 changes: 29 additions & 0 deletions docbot-controller/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use kube::{
core::WatchEvent,
Api,
};
use tracing::{error, Level};
use utils::DeploymentExt;

mod cache;
Expand Down Expand Up @@ -158,6 +159,21 @@ async fn watch_for_deployment_hook_changes(
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// construct a subscriber that prints formatted traces to stdout
let subscriber = tracing_subscriber::fmt()
// Use a more compact, abbreviated log format
.pretty()
// Display the thread ID an event was recorded on
.with_thread_ids(true)
// Don't display the event's target (module path)
.with_target(false)
.with_max_level(Level::DEBUG)
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
// Build the subscriber
.finish();

tracing::subscriber::set_global_default(subscriber)?;

let client: Client = Client::try_default()
.await
.expect("Expected a valid KUBECONFIG environment variable.");
Expand All @@ -172,6 +188,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let pod_template_service = PodTemplateService::new(client.clone());

// Watch pod template changes for better data... sometimes the API can be stale
tokio::spawn({
let pod_template_service = pod_template_service.clone();

async move {
loop {
if let Err(err) = pod_template_service.watch_for_changes().await {
error!("Found error while watching pod template changes: {:?}", err);
}
}
}
});

// Refresh the cache every minute
tokio::spawn({
let cache = cache.clone();
Expand Down
1 change: 1 addition & 0 deletions docbot-crd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ serde_json = "1.0"
lru = "0.12.1"
tokio = { version = "1.15.0", features = ["full"] }
tracing = "0.1.40"
futures = "0.3.29"
9 changes: 0 additions & 9 deletions docbot-crd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ impl DeploymentHook {
template: Some(template.clone()),
});
}
// // Otherwise use the name to look it up via the k8s api.
// let pod_template_api: Api<PodTemplate> = Api::namespaced(
// client,
// &self
// .metadata
// .namespace
// .clone()
// .unwrap_or_else(|| "default".to_string()),
// );

let namespace = &self
.metadata
Expand Down
Loading

0 comments on commit 3004e35

Please sign in to comment.