Skip to content

kernel-1095: Harden remediate.sh with pipefail and drain timeout - #5961

Open
Sebastien Tardif (SebTardif) wants to merge 3 commits into
Azure:masterfrom
SebTardif:fix/kernel-1095-harden-remediate
Open

Sebastien Tardif (SebTardif) wants to merge 3 commits into
Azure:masterfrom
SebTardif:fix/kernel-1095-harden-remediate

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Harden examples/kernel-1095-issue/remediate.sh so a failed node count cannot scale the pool to 1, and so kubectl drain cannot block reimage forever.

Problem

The script is still the documented remediation for kernel 5.4.0-1095-azure (#3350, 2022-11-19). Two issues:

  1. Missing pipefail. totalNodes=$(kubectl get nodes ... | grep $np | wc -l) succeeds with 0 if kubectl or grep fails, because wc -l exits 0. The script then runs az aks scale --node-count $((0+1)).
  2. Infinite drain. kubectl drain defaults --timeout to 0. A PDB or stuck pod blocks az vmss reimage indefinitely.

Repo Copilot instructions require set -euo pipefail for shell scripts.

Change

  • set -euo pipefail
  • Count nodes with kubectl get nodes --no-headers | wc -l (no grep in that pipeline)
  • Skip the pool when totalNodes is 0
  • List bad kernels with awk so a no-match is empty, not a failed pipeline
  • kubectl drain ... --timeout=5m
  • Read providerID with jsonpath so a missed grep cannot abort after drain (node left cordoned)
  • Quote Azure and kubectl arguments

Validation

shellcheck examples/kernel-1095-issue/remediate.sh is clean. This repo has no bash test suite for the script. I did not run it against a live cluster.

Related

set -euo pipefail so a failed kubectl|grep cannot become totalNodes=0
and scale the pool to 1. Skip empty pools, bound kubectl drain at 5m,
and read providerID via jsonpath so pipefail cannot abort after drain.

Introduced in Azure#3350 (2022-11-19).

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>

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.

🟡 Changes recommended

The script can still exit after kubectl cordon (for example on drain timeout) and leave nodes unschedulable without a cleanup trap, which is an operational risk introduced/strengthened by set -euo pipefail.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens the examples/kernel-1095-issue/remediate.sh remediation script to reduce unsafe scaling behavior and prevent kubectl drain from blocking indefinitely during kernel 5.4.0-1095-azure remediation.

Changes:

  • Switches the script to set -euo pipefail and improves quoting throughout.
  • Makes node counting and bad-kernel selection pipelines safer under pipefail (avoids grep-driven false zeros / failures).
  • Adds a kubectl drain --timeout=5m to prevent indefinite hangs and parses providerID via jsonpath.
File summaries
File Description
examples/kernel-1095-issue/remediate.sh Hardens the remediation flow (pipefail-safe counting, drain timeout, safer providerID parsing, improved quoting).
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

Comment thread examples/kernel-1095-issue/remediate.sh
Comment thread examples/kernel-1095-issue/remediate.sh Outdated
Add a per-node EXIT trap after cordon so a drain timeout or
reimage error does not leave the node unschedulable. Clear the
trap after a successful uncordon. Fix the totalNodes comment
to say wc is still used.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Copilot AI review requested due to automatic review settings September 9, 2026 20:01

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.

🟢 Approval recommended

The changes align with the stated hardening goals and reduce operational risk (pipeline failures and indefinite drains) without introducing high-risk complexity.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread examples/kernel-1095-issue/remediate.sh
Autoscaler-off pools still scaled +1 even when nodeList was empty.
Skip the pool before az aks scale so a re-run does not churn nodes.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Copilot AI review requested due to automatic review settings September 9, 2026 21:14

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.

🟢 Approval recommended

The changes directly address the stated failure modes (pipeline masking and unbounded drain) without introducing new verified correctness issues in the updated script logic.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@sjwaight

Copy link
Copy Markdown
Contributor

Pengfei Ni (@feiskyer) can you please review?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants