Skip to content

CKS/CSI: fix PVC deletion script to avoid '(standard input)' and use kubectl -o name/jsonpath - #11968

Open
Pearl1594 wants to merge 1 commit into
4.22from
delete-resources-tied-pvc
Open

CKS/CSI: fix PVC deletion script to avoid '(standard input)' and use kubectl -o name/jsonpath#11968
Pearl1594 wants to merge 1 commit into
4.22from
delete-resources-tied-pvc

Conversation

@Pearl1594

@Pearl1594 Pearl1594 commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Description

This PR fixes PVC deletion script to avoid "(standard input)" and use kubectl -o name/jsonpath

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@codecov

codecov Bot commented Nov 3, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 17.86%. Comparing base (a9b2f33) to head (459ae94).
⚠️ Report is 1 commits behind head on 4.22.

Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #11968      +/-   ##
============================================
- Coverage     17.86%   17.86%   -0.01%     
+ Complexity    16037    16036       -1     
============================================
  Files          5928     5928              
  Lines        534479   534479              
  Branches      65410    65410              
============================================
- Hits          95468    95465       -3     
- Misses       428173   428175       +2     
- Partials      10838    10839       +1     
Flag Coverage Δ
uitests 4.02% <ø> (ø)
unittests 18.92% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2025

Copy link
Copy Markdown

@Pearl1594

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Pearl1594 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 15622

@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 120 days with no activity. It may be removed by administrators of this project at any time. Remove the stale label or comment to request for removal of it to prevent this.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@Pearl1594 , anything to do here?

@weizhouapache weizhouapache left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

have not tested it

@weizhouapache weizhouapache modified the milestones: 4.23.0, 4.22.2 Jun 29, 2026
@Pearl1594

Copy link
Copy Markdown
Contributor Author

@Pearl1594 , anything to do here?

This was more of a cleanup related PR - nothing more to do @DaanHoogland - ready for review / merge..

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18411

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-16451)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 49543 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr11968-t16451-kvm-ol8.zip
Smoke tests completed. 151 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm, but I see more similarities than differences in the four changed blocks. Will it make sense to modularize a bit?

@DaanHoogland

Copy link
Copy Markdown
Contributor

also, this code is touched by the kubernetes integration tests, is it? (i.e. smoke tests suffice?)

@DaanHoogland DaanHoogland moved this from Backlog to Ready in CloudStack Testing Aug 31, 2026
@DaanHoogland

DaanHoogland commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

also, this code is touched by the kubernetes integration tests, is it? (i.e. smoke tests suffice?)

is it @Pearl1594 i.e. can we merge?

@Pearl1594

Copy link
Copy Markdown
Contributor Author

I don't believe we don't deploy the CSI driver as part of CKS test suite - so no, it isn't covered by tests @DaanHoogland

@Pearl1594

Copy link
Copy Markdown
Contributor Author

I believe it's ready for merge. I tested it almost a year ago, I think it's worthwhile testing again.

@sudo87

sudo87 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Tested this on a live CKS cluster (KVM, CSI enabled). Deployed a workload with a PVC (reclaimPolicy: Delete), then deleted the cluster to trigger this script.

With the patched script, the log correctly showed:

Processing PVC pr11968-test-pvc in namespace default (PV: pvc-... has reclaimPolicy=Delete)
  Deleting Deployment: pr11968-test-app
Deleting PVC pr11968-test-pvc in namespace default
Script completed successfully!

Deployment was identified and deleted by its actual name — no (standard input) errors. Confirms the fix works as intended.

@weizhouapache

Copy link
Copy Markdown
Member

Tested this on a live CKS cluster (KVM, CSI enabled). Deployed a workload with a PVC (reclaimPolicy: Delete), then deleted the cluster to trigger this script.

With the patched script, the log correctly showed:

Processing PVC pr11968-test-pvc in namespace default (PV: pvc-... has reclaimPolicy=Delete)
  Deleting Deployment: pr11968-test-app
Deleting PVC pr11968-test-pvc in namespace default
Script completed successfully!

Deployment was identified and deleted by its actual name — no (standard input) errors. Confirms the fix works as intended.

cool, thanks @sudo87
let's merge

@sudo87 sudo87 self-assigned this Sep 9, 2026
@sudo87 sudo87 moved this from Ready to In review in CloudStack Testing Sep 9, 2026
@weizhouapache

Copy link
Copy Markdown
Member

oh, wait
@Pearl1594
is this applicable for 4.22 too ?

@Pearl1594

Copy link
Copy Markdown
Contributor Author

oh, wait @Pearl1594 is this applicable for 4.22 too ?

Yes @weizhouapache - I've rebased it. Thanks

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Updates the PVC cleanup script to avoid grep -l on piped JSON (which emits "(standard input)") by enumerating workload resources by name and inspecting their PVC references via kubectl ... -o jsonpath.

Changes:

  • Switch workload discovery from kubectl get ... -o json | grep -l to kubectl get ... -o name loops.
  • Add per-resource kubectl get <kind> <name> -o jsonpath=... checks for PVC references across multiple workload types.
  • Extend StatefulSet checks to include both pod template volumes and volumeClaimTemplates.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +52 to +59
/opt/bin/kubectl get statefulsets -n "$namespace" -o name 2>/dev/null | \
while IFS= read -r resource; do
if [ -z "$resource" ]; then
continue
fi
name=${resource#*/}
# Check both template volumes and volumeClaimTemplates
sts_volumes=$(/opt/bin/kubectl get statefulset "$name" -n "$namespace" -o jsonpath='{.spec.template.spec.volumes[*].persistentVolumeClaim.claimName} {.spec.volumeClaimTemplates[*].metadata.name}' 2>/dev/null || echo "")
Comment on lines +37 to +38
/opt/bin/kubectl get deployments -n "$namespace" -o name 2>/dev/null | \
while IFS= read -r resource; do
Comment on lines +43 to +44
dep_volumes=$(/opt/bin/kubectl get deployment "$name" -n "$namespace" -o jsonpath='{.spec.template.spec.volumes[*].persistentVolumeClaim.claimName}' 2>/dev/null || echo "")
if [ -n "$dep_volumes" ] && echo "$dep_volumes" | grep -F -q "$pvc_name"; then
Comment on lines +37 to +46
/opt/bin/kubectl get deployments -n "$namespace" -o name 2>/dev/null | \
while IFS= read -r resource; do
if [ -z "$resource" ]; then
continue
fi
name=${resource#*/}
dep_volumes=$(/opt/bin/kubectl get deployment "$name" -n "$namespace" -o jsonpath='{.spec.template.spec.volumes[*].persistentVolumeClaim.claimName}' 2>/dev/null || echo "")
if [ -n "$dep_volumes" ] && echo "$dep_volumes" | grep -F -q "$pvc_name"; then
echo "$(timestamp) - Deleting Deployment: $name"
/opt/bin/kubectl delete deployment "$name" -n "$namespace" --ignore-not-found=true
Comment on lines +46 to 49
/opt/bin/kubectl delete deployment "$name" -n "$namespace" --ignore-not-found=true
deleted_count=$((deleted_count + 1))
fi
done
@weizhouapache

Copy link
Copy Markdown
Member

oh, wait @Pearl1594 is this applicable for 4.22 too ?

Yes @weizhouapache - I've rebased it. Thanks

thanks @Pearl1594

let's merge when smoke tests pass.

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19182

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

8 participants