Skip to content

Commit

Permalink
updated the delete conditions for removing an app's persistent volume (
Browse files Browse the repository at this point in the history
…#73)

* updated the delete conditions for removing an app's persistent volume

* updated pvc->pv

* updated pvc delete

* update pvc delete command

* updated query values

---------

Co-authored-by: alianides <[email protected]>
  • Loading branch information
alexlianides and alianides authored Jul 11, 2024
1 parent 0bd3199 commit a493170
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions modules/m_110_debugshim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ function remove_deployment_by_app_id() {
debug_log "...all previous deployments removed for '${appId}'"

debug_log "Removing volume claims for '${appId}'..."
run_a_script "kubectl get persistentvolume --output json -A | jq -r '.items[] | select(.metadata.labels.\"microsoft.azureorbital/appName\" == \"${appId}\") | {pv_name: .metadata.name, volume_claim_name: .spec.claimRef.name, volume_claim_namespace: .spec.claimRef.namespace, volume_reclaim_policy: .spec.persistentVolumeReclaimPolicy}| @base64'" pvs

for pv in $pvs; do
parse_json_line --json "${pv}" --property ".pv_name" --result pv_name
parse_json_line --json "${pv}" --property ".volume_claim_name" --result volume_claim_name
parse_json_line --json "${pv}" --property ".volume_namespace" --result volume_claim_namespace
parse_json_line --json "${pv}" --property ".volume_reclaim_policy" --result volume_reclaim_policy

debug_log "Deleting pvc '${volume_claim_name}' from namespace '${volume_claim_namespace}'..."
run_a_script "kubectl delete persistentvolumeclaim/${volume_claim_name} -n ${volume_claim_namespace} --now=true"

if [ "${volume_reclaim_policy}" = "Retain" ]; then
run_a_script "kubectl delete persistentvolume/${pv_name} --now=true"
fi

run_a_script "kubectl get persistentvolumeclaim --output json -A | jq -r '.items[] | select(.metadata.labels.\"microsoft.azureorbital/appName\" == \"${appId}\") | {pvc_name: .metadata.name, pvc_namespace: .metadata.namespace, volume_name: .spec.volumeName} | @base64'" pvcs

for pvc in $pvcs; do
parse_json_line --json "${pvc}" --property ".pvc_name" --result pvc_name
parse_json_line --json "${pvc}" --property ".volume_name" --result volume_name
parse_json_line --json "${pvc}" --property ".pvc_namespace" --result pvc_namespace
debug_log "Deleting PVC '${pvc_name}' from namespace '${pvc_namespace}'..."
run_a_script "kubectl delete persistentvolumeclaim/${pvc_name} -n ${pvc_namespace} --now=true"
run_a_script "kubectl delete persistentvolume/${volume_name} --now=true"
done

debug_log "...all volume claims for '${appId}' have been removed"
Expand Down

0 comments on commit a493170

Please sign in to comment.