refactor(chart): run the node-condition cleanup hook with sh on alpine/kubectl #2612
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #2612"
general
weight: 0.35
mchmarny
Summary
Follow-up to #2519. In #2525 the node-condition cleanup hook moved to
alpine/k8sbecausefiles/node-condition-cleanup.shneeded bash and jq, with porting the script to plain sh left for after #2467 (comment). #2467 is in now, so this does the port and points the hook atdocker.io/alpine/kubectl:1.37.2, the image the mongodb-store helpers already use. alpine/k8s:1.37.2 is ~307 MiB compressed (amd64), alpine/kubectl ~23 MiB.The script is POSIX sh now and needs kubectl, awk, grep, od, sed, wc, tr and sleep (with fractional seconds). The 5-way parallelism, the per-node lines, the summary and the NotFound skips from #2467 stay the same.
How it works without jq: it can't rebuild the conditions array, so instead of
replace /status/conditionswith a filtered copy it reads the resourceVersion and the condition types with a go-template, each type as hex bytes (printf "x%x", so it's always one line), turns the configured types into hex the same way withodand compares them in awk, byte for byte like the jq comparison on main. then it sends a JSON patch that removes only the matching entries by index (highest first), starting withreplace /metadata/resourceVersion. if the node changed between the get and the patch the API server rejects it, with a Conflict or, when another writer removed a condition and an index is past the end, a validation error (422), and the hook retries from a fresh get when the resourceVersion moved (0.1s, then 0.2s, 3 attempts as before). the old replace could drop a condition that another writer added in between, this one can't.What changes for users:
1) a configured condition type with a line break now fails the hook before anything is patched, so the post-upgrade hook and the upgrade fail. on main a line break silently ended the list (
read -rakept the first line) and the hook exited 0. it's in the README2) a Forbidden patch fails right away. any other error while the node keeps changing is retried, and after 3 attempts the hook prints
patch failed after 3 attempts while the node kept changinginstead of calling it a conflict3) if a node keeps changing for all 3 attempts the hook fails (and the Job retries via backoffLimit) instead of overwriting the other writer
4) the "could not parse node JSON" line is gone, there's no JSON to parse anymore
Ported
files/node-condition-cleanup.shto POSIX sh (no bash, no jq) as above. the conflict check is anchored toError from server (Conflict):now, like the NotFound one, so a node name with "conflict" in it doesn't trigger retriesChanged the hook command to
/bin/shandnodeConditionCleanup.imagetodocker.io/alpine/kubectl:1.37.2Updated
tests/node-condition-cleanup_test.sh: the stub kubectl is POSIX sh, prints the types as hex like kubectl'sprintf "x%x"and records the patches, the script runs under$SH(defaultsh). kept the existing cases and added: the exact patch, descending index order with a prefix lookalike, no patch when nothing matches, types like-Dash,Old_Aand a literal backslash, a type with a line break, a quote and an empty type on the node, a tab, double quote, carriage return and non-breaking space in the config, a line break in the config, a conflict that gets retried, a 422 after another writer removed a condition (second patch removes index 0 at the new resourceVersion) and with an unchanged resourceVersion, a node deleted after a failed patch, a non-conflict error while the node keeps changing, Forbidden on a busy node and a node namedgpu-conflict-7. the delayed-wait case overrideswaitwith a sh function and sources the script, sinceexport -fis bash onlyUpdated the hook case in
tests/kubectl_helper_image_test.yaml(image,/bin/sh, the go-template call, no jq) and the mirror caseUpdated
values.yamlanddocs/configuration/README.md(default image, what a replacement image needs, how to write the types) and the Makefile comment for the shell testsDidn't touch the RBAC, the hook annotations or the Job spec otherwise.
Type of Change
Component(s) Affected
Testing
make helm-lintandmake helm-testpass, and the shell test passes withsh,busybox shandbash(SH="busybox sh" bash distros/kubernetes/nvsentinel/tests/node-condition-cleanup_test.sh). i also ran the script inalpine/kubectl:1.37.2itself (amd64 + arm64) as UID 65534 with a read-only root filesystem and all capabilities dropped, with a stub kubectl in front: no bash or jq in the image, and the patch for a node withOldB Ready OldA Keepremoved indexes 2 and 0 behind its resourceVersion.+ ran it against a real kube-apiserver v1.34.1 + etcd in docker, with the chart's rendered ServiceAccount, ClusterRole and binding and the rendered container (in-cluster token, UID 65534, read-only root filesystem, no capabilities):
1) the deprecated conditions are removed and the rest is kept (messages with quotes, commas and braces, prefix lookalikes like
OldAX), and a rerun writes nothing2) a second client inserting a condition between the hook's get and patch: Conflict, retry from a fresh get, the new condition stays. the previous script in alpine/k8s drops it in the same setup
3) a second client removing a condition between the get and the patch: 422, retry, the right condition removed
4) a node deleted before the patch is skipped, and without
nodes/statusthe hook exits 1 with1 of 4 nodes failed5) a condition type with a line break (
X\nOldA) and an empty type are kept, only the realOldAnext to them is removed6) configured types with a non-breaking space, a tab and a carriage return: exactly those removed, look-alikes kept
ran that with the hook in
alpine/kubectl:1.37.2,bitnamilegacy/kubectl:1.30.6(the previous default, for anyone pinning it) andalpine/k8s:1.37.2.Checklist
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Node condition cleanup matches configured condition types exactly and retries eligible updates when a node changes during processing. Deleted nodes are skipped; failures that cannot be retried are reported.
A condition type containing a line break causes the cleanup hook to fail before modifying any node.
Configuration
The cleanup job now runs with POSIX
shand uses thekubectlimage. Bash andjqare no longer required; replacement images needsh,kubectl,od,sed, and fractional-secondsleepsupport.Documentation
Updated configuration guidance to reflect the image and utility requirements, matching behavior, and invalid condition handling.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->