Skip to content

Commit

Permalink
Release shared PVs before login
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Jun 1, 2023
1 parent 1602fdc commit 492a381
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion vine/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async fn clone_pv(
let api = Api::<PersistentVolume>::all(kube.clone());
let target_name = format!("{source_name}-{target_namespace}");
if let Some(pv) = api.get_opt(&target_name).await? {
return Ok(pv);
return release_pv(&api, pv, pp).await;
}

// get original PV
Expand Down Expand Up @@ -220,6 +220,29 @@ async fn clone_pv(
.map_err(|error| anyhow!("failed to create a PV ({source_name} => {target_name}): {error}"))
}

async fn release_pv(
api: &Api<PersistentVolume>,
mut pv: PersistentVolume,
pp: &PostParams,
) -> Result<PersistentVolume> {
if let Some(spec) = &mut pv.spec {
// apply patch
if spec.claim_ref.take().is_none() {
// skip if already patched
return Ok(pv);
}
}

// save
let name = pv.name_any();
match api.replace(&name, pp, &pv).await {
Ok(_) => Ok(pv),
Err(error) => {
bail!("failed to release the PV ({name}): {error}")
}
}
}

/// On this PV, change the `persistentVolumeReclaimPolicy` parameter to `Retain`
/// to avoid it from being deleted when you will delete PVCs.
///
Expand Down

0 comments on commit 492a381

Please sign in to comment.