Skip to content

Commit

Permalink
show partial backtrace on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
drmorr0 committed Oct 17, 2023
1 parent 9854c98 commit 0e56f4c
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 99 deletions.
22 changes: 13 additions & 9 deletions Cargo.lock

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

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ name = "simkube"
path = "lib/rust/lib.rs"

[dependencies]
anyhow = "1.0.75"
# These are actually dev dependencies of the testutils feature
httpmock = { version = "0.6.8", optional = true }
rstest = { version = "0.18.2", optional = true }
http = { version = "0.2.9", optional = true }

anyhow = { version = "1.0.75", features = ["backtrace"] }
async-recursion = "1.0.5"
chrono = "0.4.26"
clap = { version = "4.3.21", features = ["derive"] }
futures = "0.3.28"
json-patch = "1.2.0"
k8s-openapi = { version = "0.19.0", features = ["v1_27"] }
paste = "1.0.14"
regex = "1.10.2"
reqwest = { version = "0.11.18", default-features = false, features = ["json", "rustls-tls"] }
rmp-serde = "1.1.2"
rocket = { version = "0.5.0-rc.3", features = ["json", "tls"] }
Expand All @@ -43,15 +49,10 @@ serde_yaml = "0.9.25"
thiserror = "1.0.46"
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread", "signal"] }
tracing = "0.1.37"
tracing-log = "0.1.3"
tracing-subscriber = "0.3.17"
url = "2.4.1"

# These are actually dev dependencies of the testutils feature
httpmock = { version = "0.6.8", optional = true }
rstest = { version = "0.18.2", optional = true }
http = { version = "0.2.9", optional = true }
tracing-log = "0.1.3"

[dependencies.kube]
version = "0.85.0"
features = ["client", "derive", "runtime", "rustls-tls", "admission"]
Expand Down
8 changes: 4 additions & 4 deletions ctrl/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use k8s_openapi::api::batch::v1 as batchv1;
use k8s_openapi::api::core::v1 as corev1;
use kube::runtime::controller::Action;
use kube::ResourceExt;
use simkube::errors::*;
use simkube::k8s::label_selector;
use simkube::prelude::*;
use tokio::time::Duration;
use tracing::*;

use super::objects::*;
use super::*;
Expand Down Expand Up @@ -88,7 +88,7 @@ async fn setup_driver(ctx: &SimulationContext, sim: &Simulation, root: &Simulati
Ok(Action::await_change())
}

pub(crate) async fn reconcile(sim: Arc<Simulation>, ctx: Arc<SimulationContext>) -> Result<Action, ReconcileError> {
pub(crate) async fn reconcile(sim: Arc<Simulation>, ctx: Arc<SimulationContext>) -> Result<Action, AnyhowError> {
info!("got simulation object");

Check warning on line 92 in ctrl/controller.rs

View check run for this annotation

Codecov / codecov/patch

ctrl/controller.rs#L91-L92

Added lines #L91 - L92 were not covered by tests

let sim = sim.deref();
Expand All @@ -98,7 +98,7 @@ pub(crate) async fn reconcile(sim: Arc<Simulation>, ctx: Arc<SimulationContext>)
Ok(setup_driver(&ctx, sim, &root).await?)
}

pub(crate) fn error_policy(sim: Arc<Simulation>, error: &ReconcileError, _: Arc<SimulationContext>) -> Action {
error!("reconcile failed on simulation {}: {:?}", sim.namespaced_name(), error);
pub(crate) fn error_policy(sim: Arc<Simulation>, err: &AnyhowError, _: Arc<SimulationContext>) -> Action {
skerr!(err, "reconcile failed on simulation {}", sim.namespaced_name());

Check warning on line 102 in ctrl/controller.rs

View check run for this annotation

Codecov / codecov/patch

ctrl/controller.rs#L101-L102

Added lines #L101 - L102 were not covered by tests
Action::requeue(REQUEUE_ERROR_DURATION)
}
19 changes: 15 additions & 4 deletions ctrl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod controller;
mod objects;
mod trace;

use std::ops::Deref;
use std::sync::Arc;

use clap::Parser;
Expand Down Expand Up @@ -43,11 +44,21 @@ struct Options {
verbosity: String,
}

#[derive(Error, Debug)]
// This is sortof a stupid hack, because anyhow::Error doesn't derive from
// std::error::Error, but the reconcile functions require you to return a
// result that derives from std::error::Error. So we just wrap the anyhow,
// and then implement deref for it so we can get back to the underlying error
// wherever we actually care.
#[derive(Debug, Error)]
#[error(transparent)]
enum ReconcileError {
AnyhowError(#[from] anyhow::Error),
KubeApiError(#[from] kube::Error),
struct AnyhowError(#[from] anyhow::Error);

impl Deref for AnyhowError {
type Target = anyhow::Error;

fn deref(&self) -> &Self::Target {
&self.0
}

Check warning on line 61 in ctrl/main.rs

View check run for this annotation

Codecov / codecov/patch

ctrl/main.rs#L59-L61

Added lines #L59 - L61 were not covered by tests
}

#[derive(Clone)]
Expand Down
12 changes: 6 additions & 6 deletions driver/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ pub async fn handler(
) -> Json<AdmissionReview<corev1::Pod>> {
let req: AdmissionRequest<_> = match body.into_inner().try_into() {
Ok(r) => r,
Err(e) => {
error!("could not parse request: {e}");
let resp = AdmissionResponse::invalid(e);
Err(err) => {
error!("could not parse request: {err:?}");
let resp = AdmissionResponse::invalid(err);
return Json(into_pod_review(resp));
},
};
Expand All @@ -42,9 +42,9 @@ pub async fn handler(
info!("mutation successfully constructed");
r
},
Err(e) => {
error!("could not perform mutation, blocking pod object: {e}");
AdmissionResponse::from(&req).deny(e)
Err(err) => {
error!("could not perform mutation, blocking pod object: {err:?}");
AdmissionResponse::from(&req).deny(err)
},
};
}
Expand Down
104 changes: 52 additions & 52 deletions k8s/poetry.lock

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

2 changes: 1 addition & 1 deletion k8s/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["David Morrison <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.11"
cdk8s = "^2.24.0"
fireconfig = { git = "https://github.com/acrlabs/fireconfig", tag = "v0.2.1" }
fireconfig = { git = "https://github.com/acrlabs/fireconfig", tag = "v0.2.2" }

[tool.poetry.group.dev.dependencies]
mypy = "^1.4.1"
Expand Down
Loading

0 comments on commit 0e56f4c

Please sign in to comment.