CKS/CSI: fix PVC deletion script to avoid '(standard input)' and use kubectl -o name/jsonpath - #11968
CKS/CSI: fix PVC deletion script to avoid '(standard input)' and use kubectl -o name/jsonpath#11968Pearl1594 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
@blueorangutan package |
|
@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. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 15622 |
|
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. |
|
@Pearl1594 , anything to do here? |
weizhouapache
left a comment
There was a problem hiding this comment.
code lgtm
have not tested it
This was more of a cleanup related PR - nothing more to do @DaanHoogland - ready for review / merge.. |
|
@blueorangutan package |
|
@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. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18411 |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-16451)
|
DaanHoogland
left a comment
There was a problem hiding this comment.
clgtm, but I see more similarities than differences in the four changed blocks. Will it make sense to modularize a bit?
|
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? |
|
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 |
|
I believe it's ready for merge. I tested it almost a year ago, I think it's worthwhile testing again. |
|
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: Deployment was identified and deleted by its actual name — no (standard input) errors. Confirms the fix works as intended. |
cool, thanks @sudo87 |
|
oh, wait |
…kubectl -o name/jsonpath
fdd4ce4 to
459ae94
Compare
Yes @weizhouapache - I've rebased it. Thanks |
There was a problem hiding this comment.
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 -ltokubectl get ... -o nameloops. - 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.
| /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 "") |
| /opt/bin/kubectl get deployments -n "$namespace" -o name 2>/dev/null | \ | ||
| while IFS= read -r resource; do |
| 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 |
| /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 |
| /opt/bin/kubectl delete deployment "$name" -n "$namespace" --ignore-not-found=true | ||
| deleted_count=$((deleted_count + 1)) | ||
| fi | ||
| done |
thanks @Pearl1594 let's merge when smoke tests pass. @blueorangutan package |
|
@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. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19182 |



Description
This PR fixes PVC deletion script to avoid "(standard input)" and use kubectl -o name/jsonpath
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?