Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalizer helper #475

Merged
merged 11 commits into from
Jul 2, 2021
Prev Previous commit
Next Next commit
Don't panic when trying to finalize unnamed objects
  • Loading branch information
nightkr committed Jun 29, 2021
commit 2003e86c4880d660e88f2cd23a8cb51dbc049154
8 changes: 5 additions & 3 deletions kube-runtime/src/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kube::{
Api,
};
use serde::{de::DeserializeOwned, Serialize};
use snafu::{ResultExt, Snafu};
use snafu::{OptionExt, ResultExt, Snafu};
use std::{error::Error as StdError, fmt::Debug};

#[derive(Debug, Snafu)]
Expand All @@ -23,6 +23,8 @@ where
AddFinalizer { source: kube::Error },
#[snafu(display("failed to remove finalizer: {}", source))]
RemoveFinalizer { source: kube::Error },
#[snafu(display("object has no name"))]
UnnamedObject,
}

struct FinalizerState {
Expand Down Expand Up @@ -118,7 +120,7 @@ where
is_deleting: true,
} => {
// Cleanup reconciliation must succeed before it's safe to remove the finalizer
let name = obj.metadata().name.clone().unwrap();
let name = obj.metadata().name.clone().context(UnnamedObject)?;
let action = reconcile(Event::Cleanup(obj))
.into_future()
.await
Expand Down Expand Up @@ -167,7 +169,7 @@ where
})]
});
api.patch::<K>(
obj.metadata().name.as_deref().unwrap(),
obj.metadata().name.as_deref().context(UnnamedObject)?,
&PatchParams::default(),
&Patch::Json(patch),
)
Expand Down