Skip to content

Commit 3e69926

Browse files
author
Luca Palmieri
committed
Ensure that any span emitted in error_policy is a child span of the root span for the respective reconciliation run.
1 parent fb551cc commit 3e69926

File tree

1 file changed

+9
-9
lines changed
  • kube-runtime/src/controller

1 file changed

+9
-9
lines changed

kube-runtime/src/controller/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,16 @@ where
268268
move |s| {
269269
Runner::new(scheduler(s), move |request| {
270270
let request = request.clone();
271+
let reconciler_span = info_span!("reconciling object", "object.ref" = %request.obj_ref, object.reason = tracing::field::Empty);
271272
match store.get(&request.obj_ref) {
272273
Some(obj) => {
273-
let reconciler_span = info_span!("reconciling object", "object.ref" = %request.obj_ref, object.reason = %request.reason);
274+
reconciler_span.record("object.reason", &tracing::field::display(&request.reason));
274275
reconciler_span.in_scope(|| reconciler(obj, context.clone()))
275276
.into_future()
276-
.instrument(reconciler_span)
277+
.instrument(reconciler_span.clone())
277278
// Reconciler errors are OK from the applier's PoV, we need to apply the error policy
278279
// to them separately
279-
.map(|res| Ok((request.obj_ref, res)))
280+
.map(|res| Ok((request.obj_ref, res, reconciler_span)))
280281
.left_future()
281282
},
282283
None => future::err(
@@ -295,14 +296,14 @@ where
295296
)
296297
.on_complete(async { tracing::debug!("applier runner-merge terminated") })
297298
// finally, for each completed reconcile call:
298-
.and_then(move |(obj_ref, reconciler_result)| {
299+
.and_then(move |(obj_ref, reconciler_result, reconciler_span)| {
299300
let (ReconcilerAction { requeue_after }, requeue_reason) = match &reconciler_result {
300301
Ok(action) =>
301302
// do what user told us
302303
(action.clone(), ReconcileReason::ReconcilerRequestedRetry),
303304
Err(err) =>
304305
// reconciler fn call failed
305-
(error_policy(err, err_context.clone()), ReconcileReason::ErrorPolicyRequestedRetry),
306+
(reconciler_span.in_scope(|| error_policy(err, err_context.clone())), ReconcileReason::ErrorPolicyRequestedRetry),
306307
};
307308
let mut scheduler_tx = scheduler_tx.clone();
308309
async move {
@@ -486,12 +487,11 @@ where
486487
/// To watch the full set of `Child` objects in the given `Api` scope, you can use [`ListParams::default`].
487488
///
488489
/// [`OwnerReference`]: k8s_openapi::apimachinery::pkg::apis::meta::v1::OwnerReference
489-
pub fn owns<Child: Clone + Resource<DynamicType=()> + DeserializeOwned + Debug + Send + 'static>(
490+
pub fn owns<Child: Clone + Resource<DynamicType = ()> + DeserializeOwned + Debug + Send + 'static>(
490491
self,
491492
api: Api<Child>,
492493
lp: ListParams,
493-
) -> Self
494-
{
494+
) -> Self {
495495
self.owns_with(api, (), lp)
496496
}
497497

@@ -529,7 +529,7 @@ where
529529
/// to watch - in the Api's configured scope - and run through the custom mapper.
530530
/// To watch the full set of `Watched` objects in given the `Api` scope, you can use [`ListParams::default`].
531531
pub fn watches<
532-
Other: Clone + Resource<DynamicType=()> + DeserializeOwned + Debug + Send + 'static,
532+
Other: Clone + Resource<DynamicType = ()> + DeserializeOwned + Debug + Send + 'static,
533533
I: 'static + IntoIterator<Item = ObjectRef<K>>,
534534
>(
535535
self,

0 commit comments

Comments
 (0)