Skip to content

Commit

Permalink
Propagate Arc through the finalizer reconciler helper
Browse files Browse the repository at this point in the history
Builds on kube-rs#786, which did the minimum viable thing by moving the clone into the
finalizer module.
  • Loading branch information
nightkr committed Jan 25, 2022
1 parent cd510fd commit cb987e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions examples/secret_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use kube::{
finalizer::{finalizer, Event},
},
};
use std::time::Duration;
use std::{sync::Arc, time::Duration};
use thiserror::Error;

#[derive(Debug, Error)]
Expand All @@ -37,7 +37,7 @@ fn secret_name_for_configmap(cm: &ConfigMap) -> Result<String> {
))
}

async fn apply(cm: ConfigMap, secrets: &kube::Api<Secret>) -> Result<ReconcilerAction> {
async fn apply(cm: Arc<ConfigMap>, secrets: &kube::Api<Secret>) -> Result<ReconcilerAction> {
println!("Reconciling {:?}", cm);
let secret_name = secret_name_for_configmap(&cm)?;
secrets
Expand All @@ -49,8 +49,8 @@ async fn apply(cm: ConfigMap, secrets: &kube::Api<Secret>) -> Result<ReconcilerA
name: Some(secret_name.clone()),
..ObjectMeta::default()
},
string_data: cm.data,
data: cm.binary_data,
string_data: cm.data.clone(),
data: cm.binary_data.clone(),
..Secret::default()
}),
)
Expand All @@ -59,7 +59,7 @@ async fn apply(cm: ConfigMap, secrets: &kube::Api<Secret>) -> Result<ReconcilerA
Ok(ReconcilerAction { requeue_after: None })
}

async fn cleanup(cm: ConfigMap, secrets: &kube::Api<Secret>) -> Result<ReconcilerAction> {
async fn cleanup(cm: Arc<ConfigMap>, secrets: &kube::Api<Secret>) -> Result<ReconcilerAction> {
println!("Cleaning up {:?}", cm);
secrets
.delete(&secret_name_for_configmap(&cm)?, &DeleteParams::default())
Expand Down
8 changes: 4 additions & 4 deletions kube-runtime/src/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ where
FinalizerState {
finalizer_index: Some(_),
is_deleting: false,
} => reconcile(Event::Apply(obj.as_ref().clone()))
} => reconcile(Event::Apply(obj))
.into_future()
.await
.map_err(Error::ApplyFailed),
Expand All @@ -123,7 +123,7 @@ where
} => {
// Cleanup reconciliation must succeed before it's safe to remove the finalizer
let name = obj.meta().name.clone().ok_or(Error::UnnamedObject)?;
let action = reconcile(Event::Cleanup(obj.as_ref().clone()))
let action = reconcile(Event::Cleanup(obj))
.into_future()
.await
// Short-circuit, so that we keep the finalizer if cleanup fails
Expand Down Expand Up @@ -200,7 +200,7 @@ pub enum Event<K> {
/// - The object is updated
/// - The reconciliation fails
/// - The grinch attacks
Apply(K),
Apply(Arc<K>),
/// The object is being deleted, and the reconciler should remove all resources that it owns.
///
/// This must be idempotent, since it may be recalled if, for example (this list is non-exhaustive):
Expand All @@ -209,5 +209,5 @@ pub enum Event<K> {
/// - The reconciliation fails
/// - Another finalizer was removed in the meantime
/// - The grinch's heart grows a size or two
Cleanup(K),
Cleanup(Arc<K>),
}

0 comments on commit cb987e1

Please sign in to comment.