From eb9e275411fe1fe96e2d0a799c2d18959ca0cf37 Mon Sep 17 00:00:00 2001 From: Xudong Sun Date: Thu, 3 Oct 2024 20:08:14 -0500 Subject: [PATCH] Rename Signed-off-by: Xudong Sun --- src/v2/shim_layer/controller_runtime.rs | 51 ++++++++++++------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/v2/shim_layer/controller_runtime.rs b/src/v2/shim_layer/controller_runtime.rs index f8474b50..5118b1d1 100644 --- a/src/v2/shim_layer/controller_runtime.rs +++ b/src/v2/shim_layer/controller_runtime.rs @@ -35,8 +35,8 @@ use vstd::{string::*, view::*}; // run_controller prepares and runs the controller. It requires: // K: the custom resource type -// ReconcilerType: the reconciler type -pub async fn run_controller(fault_injection: bool) -> Result<()> +// R: the reconciler type +pub async fn run_controller(fault_injection: bool) -> Result<()> where K: Clone + Resource @@ -48,19 +48,19 @@ where + Sync + 'static, K::DynamicType: Default + Eq + Hash + Clone + Debug + Unpin, - ReconcilerType: Reconciler + Send + Sync, - ReconcilerType::K: ResourceWrapper + Send, - ReconcilerType::S: Send, - ReconcilerType::EReq: Send, - ReconcilerType::EResp: Send, - E: ExternalShimLayer, + R: Reconciler + Send + Sync, + R::K: ResourceWrapper + Send, + R::S: Send, + R::EReq: Send, + R::EResp: Send, + E: ExternalShimLayer, { let client = Client::try_default().await?; let crs = Api::::all(client.clone()); // Build the async closure on top of reconcile_with let reconcile = |cr: Arc, ctx: Arc| async move { - return reconcile_with::(cr, ctx, fault_injection).await; + return reconcile_with::(cr, ctx, fault_injection).await; }; info!("starting controller"); @@ -79,15 +79,15 @@ where Ok(()) } -// reconcile_with implements the reconcile function by repeatedly invoking ReconcilerType::reconcile_core. +// reconcile_with implements the reconcile function by repeatedly invoking R::reconcile_core. // reconcile_with will be invoked by kube-rs whenever kube-rs's watcher receives any relevant event to the controller. -// In each invocation, reconcile_with invokes ReconcilerType::reconcile_core in a loop: -// it starts with ReconcilerType::reconcile_init_state, and in each iteration it invokes ReconcilerType::reconcile_core +// In each invocation, reconcile_with invokes R::reconcile_core in a loop: +// it starts with R::reconcile_init_state, and in each iteration it invokes R::reconcile_core // with the new state returned by the previous invocation. -// For each request from ReconcilerType::reconcile_core, it invokes kube-rs APIs to send the request to the Kubernetes API. -// It ends the loop when the ReconcilerType reports the reconcile is done (ReconcilerType::reconcile_done) -// or encounters error (ReconcilerType::reconcile_error). -pub async fn reconcile_with( +// For each request from R::reconcile_core, it invokes kube-rs APIs to send the request to the Kubernetes API. +// It ends the loop when the R reports the reconcile is done (R::reconcile_done) +// or encounters error (R::reconcile_error). +pub async fn reconcile_with( cr: Arc, ctx: Arc, fault_injection: bool, @@ -100,9 +100,9 @@ where + Debug + Serialize, K::DynamicType: Default + Clone + Debug, - ReconcilerType: Reconciler, - ReconcilerType::K: ResourceWrapper, - E: ExternalShimLayer, + R: Reconciler, + R::K: ResourceWrapper, + E: ExternalShimLayer, { let client = &ctx.client; @@ -147,9 +147,9 @@ where deps_hack::k8s_openapi::serde_json::to_string(&cr).unwrap() ); - let cr_wrapper = ReconcilerType::K::from_kube(cr); - let mut state = ReconcilerType::reconcile_init_state(); - let mut resp_option: Option> = None; + let cr_wrapper = R::K::from_kube(cr); + let mut state = R::reconcile_init_state(); + let mut resp_option: Option> = None; // check_fault_timing is only set to true right after the controller issues any create, update or delete request, // or external request let mut check_fault_timing: bool; @@ -158,17 +158,16 @@ where loop { check_fault_timing = false; // If reconcile core is done, then breaks the loop - if ReconcilerType::reconcile_done(&state) { + if R::reconcile_done(&state) { info!("{} done", log_header); break; } - if ReconcilerType::reconcile_error(&state) { + if R::reconcile_error(&state) { warn!("{} error", log_header); return Err(Error::ReconcileCoreError); } // Feed the current reconcile state and get the new state and the pending request - let (state_prime, request_option) = - ReconcilerType::reconcile_core(&cr_wrapper, resp_option, state); + let (state_prime, request_option) = R::reconcile_core(&cr_wrapper, resp_option, state); // Pattern match the request and send requests to the Kubernetes API via kube-rs methods match request_option { Some(request) => match request {