Skip to content

Commit b1e11d7

Browse files
upd clean
1 parent 375fb80 commit b1e11d7

3 files changed

Lines changed: 31 additions & 14 deletions

File tree

src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,12 @@ async fn reconcile_recovery(
234234
// This ensures we can update the status regardless of where it fails.
235235
let reconcile_result: Result<(), Error> = async {
236236
let store = objectstorage::initialize_object_store(&cr.spec.cloud_provider).await?;
237-
let file = objectstorage::get_latest_file_content(store.into(), "mylocalcluster")
238-
.await?
239-
.unwrap();
237+
let file = objectstorage::get_latest_file_content(
238+
store.into(),
239+
&cr.spec.protected_cluster.clone(),
240+
)
241+
.await?
242+
.unwrap();
240243

241244
let bundle = storage::deserialize_storage_bundle(file.clone())?;
242245

src/resource.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ where
386386
for resource in existing {
387387
let name = resource.name_any();
388388
if !desired_names.contains(&name) {
389-
390-
// 1. If it has a deletion timestamp, it's already hanging.
389+
// 1. If it has a deletion timestamp, it's already hanging.
391390
// We must clear finalizers to let it vanish.
392391
if resource.metadata().deletion_timestamp.is_some() {
393392
info!(resource = %name, "Resource is terminating; force-clearing all finalizers");
@@ -396,16 +395,18 @@ where
396395
"finalizers": null
397396
}
398397
});
399-
let _ = api.patch(&name, &PatchParams::default(), &Patch::Merge(&purge_patch)).await;
398+
let _ = api
399+
.patch(&name, &PatchParams::default(), &Patch::Merge(&purge_patch))
400+
.await;
400401
continue;
401402
}
402403

403404
// 2. Not terminating yet? Initiate deletion.
404405
info!(resource = %name, "Deleting orphaned cluster resource");
405-
406+
406407
// We use Foreground propagation to ensure children are handled
407-
let dp = DeleteParams::foreground();
408-
408+
let dp = DeleteParams::foreground();
409+
409410
match api.delete(&name, &dp).await {
410411
Ok(_) => {
411412
// 3. Immediately follow up with a finalizer wipe to prevent hanging
@@ -414,7 +415,9 @@ where
414415
"finalizers": null
415416
}
416417
});
417-
let _ = api.patch(&name, &PatchParams::default(), &Patch::Merge(&purge_patch)).await;
418+
let _ = api
419+
.patch(&name, &PatchParams::default(), &Patch::Merge(&purge_patch))
420+
.await;
418421
}
419422
Err(kube::Error::Api(e)) if e.code == 404 => {
420423
info!(resource = %name, "Resource already deleted, skipping");
@@ -448,7 +451,14 @@ pub async fn gc_namespaced_resources<T>(
448451
desired_resources: &HashSet<(String, String)>, // (Namespace, Name)
449452
) -> Result<(), kube::Error>
450453
where
451-
T: Clone + Debug + DeserializeOwned + Serialize + Default + Send + Sync + 'static
454+
T: Clone
455+
+ Debug
456+
+ DeserializeOwned
457+
+ Serialize
458+
+ Default
459+
+ Send
460+
+ Sync
461+
+ 'static
452462
+ Resource<DynamicType = (), Scope = NamespaceResourceScope>
453463
+ Metadata<Ty = ObjectMeta>,
454464
{
@@ -468,7 +478,9 @@ where
468478
if resource.metadata().deletion_timestamp.is_some() {
469479
info!(resource = %name, namespace = %ns, "Orphaned resource is terminating; force-clearing finalizers");
470480
let purge_patch = serde_json::json!({ "metadata": { "finalizers": null } });
471-
let _ = ns_api.patch(&name, &PatchParams::default(), &Patch::Merge(&purge_patch)).await;
481+
let _ = ns_api
482+
.patch(&name, &PatchParams::default(), &Patch::Merge(&purge_patch))
483+
.await;
472484
continue;
473485
}
474486

@@ -478,7 +490,9 @@ where
478490
Ok(_) => {
479491
// 3. Force wipe finalizers to ensure cleanup
480492
let purge_patch = serde_json::json!({ "metadata": { "finalizers": null } });
481-
let _ = ns_api.patch(&name, &PatchParams::default(), &Patch::Merge(&purge_patch)).await;
493+
let _ = ns_api
494+
.patch(&name, &PatchParams::default(), &Patch::Merge(&purge_patch))
495+
.await;
482496
}
483497
Err(kube::Error::Api(e)) if e.code == 404 => continue,
484498
Err(e) => return Err(e),

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::path::Path;
77
use tracing::*;
88

99
use k8s_openapi::api::core::v1::{PersistentVolume, PersistentVolumeClaim};
10-
use kube::core::ObjectMeta;
1110
use kube::Error;
11+
use kube::core::ObjectMeta;
1212

1313
/// Generic metadata cleaner for any Kubernetes resource
1414
fn clean_metadata(mut meta: ObjectMeta, keep_namespace: bool) -> ObjectMeta {

0 commit comments

Comments
 (0)