diff --git a/Cargo.lock b/Cargo.lock index a28070f..47ede1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -380,7 +380,7 @@ dependencies = [ [[package]] name = "controller" -version = "0.12.1" +version = "0.12.2" dependencies = [ "actix-web", "chrono", @@ -982,9 +982,9 @@ dependencies = [ [[package]] name = "k8s-openapi" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0489fc937cc7616a9abfa61bf39c250d7e32e1325ef028c8d9278dd24ea395b3" +checksum = "d2ae2c04fcee6b01b04e3aadd56bb418932c8e0a9d8a93f48bc68c6bdcdb559d" dependencies = [ "base64", "bytes", @@ -996,9 +996,9 @@ dependencies = [ [[package]] name = "kube" -version = "0.72.0" +version = "0.73.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "977951a1d7dbce4c6f9c2cbed0711f568df9944010fafa88161a20f7e5163bd3" +checksum = "60f11922081d37d1af75ae6b6b73b0b170ad169197c7a4a30e94e805ceff2a64" dependencies = [ "k8s-openapi", "kube-client", @@ -1009,9 +1009,9 @@ dependencies = [ [[package]] name = "kube-client" -version = "0.72.0" +version = "0.73.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625e8a89c79dd4e590217838f32274ccbb0f4ecc1db181f84aba3df635fca729" +checksum = "bcd54b663fef0f0bdc75666821262cd8bee03ffa45ded04cee0f07d2ba0288f0" dependencies = [ "base64", "bytes", @@ -1044,9 +1044,9 @@ dependencies = [ [[package]] name = "kube-core" -version = "0.72.0" +version = "0.73.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0491dcd9adca79a96c63404aa978137f5fe1d3db5dcb6e5c0b073f915dbdd49d" +checksum = "1eef68b0918b741d0cb20a54ffc06b197770584fa417180af4b398f848a381e6" dependencies = [ "chrono", "form_urlencoded", @@ -1062,9 +1062,9 @@ dependencies = [ [[package]] name = "kube-derive" -version = "0.72.0" +version = "0.73.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f19faefec284e5eec6680c74cd54d29823f38f0cf8811d54265877e1963996ad" +checksum = "3a92635af3079b229cc54fe6ba82349e1e23f1a53487f67fcbdf51db644b13eb" dependencies = [ "darling", "proc-macro2", @@ -1075,9 +1075,9 @@ dependencies = [ [[package]] name = "kube-runtime" -version = "0.72.0" +version = "0.73.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb67002cbacd6cd99d1b1d0890785a84b6408158972f2561317bc4cdc06c981e" +checksum = "cce6c2a4ae58f1610bbf639280110035ab2ac624af112b5239851c793e1af0c0" dependencies = [ "ahash", "backoff", diff --git a/Cargo.toml b/Cargo.toml index c8d79eb..e6c5de2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "controller" -version = "0.12.1" +version = "0.12.2" authors = ["clux "] edition = "2021" default-run = "controller" @@ -29,7 +29,7 @@ telemetry = ["tonic", "opentelemetry-otlp"] actix-web = "4.0.1" futures = "0.3.21" tokio = { version = "1.18.2", features = ["macros", "rt-multi-thread"] } -k8s-openapi = { version = "0.14.0", features = ["v1_22"], default-features = false } +k8s-openapi = { version = "0.15.0", features = ["v1_23"], default-features = false } serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" chrono = { version = "0.4.19", features = ["serde"] } @@ -51,8 +51,9 @@ tonic = { version = "0.6.2", optional = true } [dependencies.kube] features = ["runtime", "client", "derive"] -version = "0.72.0" +version = "0.73.0" # testing new releases - ignore #git = "https://github.com/kube-rs/kube-rs.git" -#rev = "7715cabd4d1976493e6b8949471f283df927a79e" +#rev = "8dcd5c0865ad0a40520519032119fbe4ea5f85f7" +#path = "../kube-rs/kube" diff --git a/src/manager.rs b/src/manager.rs index c8abd4b..789aa53 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -6,7 +6,7 @@ use kube::{ api::{Api, ListParams, Patch, PatchParams, ResourceExt}, client::Client, runtime::{ - controller::{Action, Context, Controller}, + controller::{Action, Controller}, events::{Event, EventType, Recorder, Reporter}, }, CustomResource, Resource, @@ -38,7 +38,6 @@ pub struct DocumentSpec { #[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] pub struct DocumentStatus { hidden: bool, - //last_updated: Option>, } impl Document { @@ -62,19 +61,20 @@ struct Data { metrics: Metrics, } + #[instrument(skip(ctx, doc), fields(trace_id))] -async fn reconcile(doc: Arc, ctx: Context) -> Result { +async fn reconcile(doc: Arc, ctx: Arc) -> Result { let trace_id = telemetry::get_trace_id(); Span::current().record("trace_id", &field::display(&trace_id)); let start = Instant::now(); - ctx.get_ref().metrics.reconciliations.inc(); + ctx.metrics.reconciliations.inc(); - let client = ctx.get_ref().client.clone(); - ctx.get_ref().state.write().await.last_event = Utc::now(); - let reporter = ctx.get_ref().state.read().await.reporter.clone(); + let client = ctx.client.clone(); + ctx.state.write().await.last_event = Utc::now(); + let reporter = ctx.state.read().await.reporter.clone(); let recorder = Recorder::new(client.clone(), reporter, doc.object_ref(&())); - let name = ResourceExt::name(doc.as_ref()); - let ns = ResourceExt::namespace(doc.as_ref()).expect("doc is namespaced"); + let name = doc.name(); + let ns = doc.namespace().unwrap(); let docs: Api = Api::namespaced(client, &ns); let should_hide = doc.spec.hide; @@ -97,7 +97,6 @@ async fn reconcile(doc: Arc, ctx: Context) -> Result, ctx: Context) -> Result, ctx: Context) -> Result) -> Action { +fn error_policy(error: &Error, ctx: Arc) -> Action { warn!("reconcile failed: {:?}", error); - ctx.get_ref().metrics.failures.inc(); + ctx.metrics.failures.inc(); Action::requeue(Duration::from_secs(5 * 60)) } @@ -190,7 +188,7 @@ impl Manager { let client = Client::try_default().await.expect("create client"); let metrics = Metrics::new(); let state = Arc::new(RwLock::new(State::new())); - let context = Context::new(Data { + let context = Arc::new(Data { client: client.clone(), metrics: metrics.clone(), state: state.clone(),