Skip to content

fix: validate Windows node reset task result#8970

Open
r2k1 wants to merge 1 commit into
mainfrom
r2k1-fix-windows-node-reset-result
Open

fix: validate Windows node reset task result#8970
r2k1 wants to merge 1 commit into
mainfrom
r2k1-fix-windows-node-reset-result

Conversation

@r2k1

@r2k1 r2k1 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Windows NodePrep currently treats the k8s-restart-job scheduled task returning to Ready as success. Ready only means the task is idle: it can also be observed before the new run starts or after a failed run.

This change:

  • waits for a new task run by requiring LastRunTime to change;
  • fails CSE when LastTaskResult is nonzero;
  • fails CSE when kubelet is not running after the task completes;
  • adds Pester coverage for the successful, pre-start Ready, failed-task, and stopped-kubelet paths.

Which issue(s) this PR fixes:

N/A

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2ba2b88c-27a6-4f9b-9fd5-bf757a9d31c2

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.

Pull request overview

This PR hardens Windows NodePrep’s handling of the k8s-restart-job scheduled task by validating that a new task run occurred and that it completed successfully, and by adding Pester coverage for key success/failure paths.

Changes:

  • Add Start-NodeResetScriptTask helper to wait for a new scheduled-task run and validate LastTaskResult and kubelet status.
  • Refactor NodePrep to call the new helper instead of inlining task polling logic.
  • Add Pester tests covering success, pre-start Ready, failed task result, and kubelet-not-running scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
parts/windows/windowscsehelper.ps1 Introduces Start-NodeResetScriptTask to validate task completion using LastRunTime/LastTaskResult and kubelet state.
parts/windows/kuberneteswindowssetup.ps1 Replaces inline scheduled-task wait logic with a call to Start-NodeResetScriptTask from NodePrep.
parts/windows/windowscsehelper.tests.ps1 Adds Pester coverage for success and failure modes of Start-NodeResetScriptTask.

return [pscustomobject]@{ LastRunTime = [datetime]"2026-01-02"; LastTaskResult = 1 }
}

{ Start-NodeResetScriptTask } | Should -Throw "*failed with result [1]*"
Comment on lines +335 to +338
$kubeletService = Get-Service -Name "kubelet" -ErrorAction SilentlyContinue
if ($null -eq $kubeletService -or $kubeletService.Status -ne "Running") {
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_START_NODE_RESET_SCRIPT_TASK -ErrorMessage "kubelet service is not running after NodeResetScriptTask completed"
}
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.

2 participants