← Back to Pull requests

refactor(chart): run the node-condition cleanup hook with sh on alpine/kubectl #2612

Closed
unknown closed this pull request without merging on Dec 04, 2026 15:45 UTC
View on GitHub
unknown unknown commented on Dec 02, 2026 07:43 UTC
Author

Summary

Follow-up to #2519. In #2525 the node-condition cleanup hook moved to alpine/k8s because files/node-condition-cleanup.sh needed 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 at docker.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/conditions with 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 with od and 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 with replace /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 -ra kept the first line) and the hook exited 0. it's in the README
2) 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 changing instead of calling it a conflict
3) 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.sh to POSIX sh (no bash, no jq) as above. the conflict check is anchored to Error from server (Conflict): now, like the NotFound one, so a node name with "conflict" in it doesn't trigger retries
Changed the hook command to /bin/sh and nodeConditionCleanup.image to docker.io/alpine/kubectl:1.37.2
Updated tests/node-condition-cleanup_test.sh: the stub kubectl is POSIX sh, prints the types as hex like kubectl's printf "x%x" and records the patches, the script runs under $SH (default sh). 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_A and 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 named gpu-conflict-7. the delayed-wait case overrides wait with a sh function and sources the script, since export -f is bash only
Updated the hook case in tests/kubectl_helper_image_test.yaml (image, /bin/sh, the go-template call, no jq) and the mirror case
Updated values.yaml and docs/configuration/README.md (default image, what a replacement image needs, how to write the types) and the Makefile comment for the shell tests

Didn't touch the RBAC, the hook annotations or the Job spec otherwise.

Type of Change


  • 🐛 Bug fix

  • ✨ New feature

  • 💥 Breaking change

  • 📚 Documentation

  • 🔧 Refactoring

  • 🔨 Build/CI
  • Component(s) Affected


  • Health Monitor

  • Core Service

  • Fault Management

  • Janitor

  • Deployment/Config

  • API/Interface

  • Preflight

  • Plugins

  • Documentation/CI

  • New Component

  • Multiple Components

  • Other
  • Testing


  • Tests pass locally

  • Manual testing completed

  • No breaking changes (or documented)
  • make helm-lint and make helm-test pass, and the shell test passes with sh, busybox sh and bash (SH="busybox sh" bash distros/kubernetes/nvsentinel/tests/node-condition-cleanup_test.sh). i also ran the script in alpine/kubectl:1.37.2 itself (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 with OldB Ready OldA Keep removed 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 nothing
    2) 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/status the hook exits 1 with 1 of 4 nodes failed
    5) a condition type with a line break (X\nOldA) and an empty type are kept, only the real OldA next to them is removed
    6) 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) and alpine/k8s:1.37.2.

    Checklist


  • Self-review completed

  • Documentation updated (if needed)

  • Ready for review
  • <!-- 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 sh and uses the kubectl image. Bash and jq are no longer required; replacement images need sh, kubectl, od, sed, and fractional-second sleep support.
    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 -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: mchmarny Review duration: 3362m
    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
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%