fix(windows-cse): check exit codes of external commands to honour try/catch#8133
Open
timmy-wright wants to merge 3 commits intomainfrom
Open
fix(windows-cse): check exit codes of external commands to honour try/catch#8133timmy-wright wants to merge 3 commits intomainfrom
timmy-wright wants to merge 3 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Windows CSE reliability by ensuring failures from native executables (which only set $LASTEXITCODE and don’t throw) are surfaced as exceptions so existing try/catch blocks can handle them, and it updates the generated CustomData snapshots accordingly.
Changes:
- Add
$LASTEXITCODEchecks after varioussc.exe,reg.exe,icacls,netsh, andnssm.exeinvocations andthrowon non-zero exit codes. - Ensure
reg.exe importfailures inside an existingtry/catchbecome catchable. - Regenerate/update
pkg/agent/testdata/**/CustomDatasnapshots to reflect script changes.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| staging/cse/windows/windowsciliumnetworkingfunc.ps1 | Throw on non-zero exit code after invoking the Windows Cilium install script. |
| staging/cse/windows/kubeletfunc.ps1 | Add exit-code checks for nssm.exe install/configure and DependOnService operations. |
| staging/cse/windows/containerdfunc.ps1 | Add exit-code checks for sc.exe delete and nssm.exe install/configure for containerd. |
| staging/cse/windows/configfunc.ps1 | Add exit-code checks for sc.exe failure, reg.exe import, icacls, and nssm.exe service creation/configuration (csi-proxy, hosts-config-agent). |
| parts/windows/kuberneteswindowssetup.ps1 | Add exit-code checks for icacls.exe ACL updates and netsh advfirewall disable. |
| pkg/agent/testdata/AKSWindows23H2Gen2+NextGenNetworkingNoConfig/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows23H2Gen2+NextGenNetworkingDisabled/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows23H2Gen2+NextGenNetworking/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+ootcredentialprovider/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+SecurityProfile/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+ManagedIdentity/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+KubeletServingCertificateRotation/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+KubeletClientTLSBootstrapping/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+K8S119/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+K8S119+FIPS/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+K8S119+CSI/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+K8S118/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+K8S117/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+K8S116/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+EnablePrivateClusterHostsConfigAgent/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+CustomVnet/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+CustomCloud/CustomData | Snapshot update to include new exit-code checks. |
| pkg/agent/testdata/AKSWindows2019+CustomCloud+ootcredentialprovider/CustomData | Snapshot update to include new exit-code checks. |
db957f9 to
c9b61f0
Compare
a9136ec to
4fde3cb
Compare
8db83e5 to
95d02f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Native executables in PowerShell set
$LASTEXITCODEon failure but do not throw exceptions, sotry/catchblocks silently swallow failures from commands likeicacls.exe,sc.exe,nssm.exe,netsh, andreg.exe.This PR adds
if ($LASTEXITCODE -ne 0) { throw "..." }checks after each unchecked external command call so that failures propagate as exceptions through the call stack.Changes
parts/windows/kuberneteswindowssetup.ps1icacls.exe(x4),netsh advfirewallstaging/cse/windows/configfunc.ps1sc.exe failure(x3),reg.exe importin try/catch that did not catch it,icacls(x4),nssm.exe install+configurefor csi-proxy and hosts-config-agentstaging/cse/windows/kubeletfunc.ps1nssm.exe install+configurefor Kubelet and Kubeproxy,Invoke-Expressionnssm DependOnServicestaging/cse/windows/containerdfunc.ps1sc.exe delete,nssm.exe install+configurefor containerdstaging/cse/windows/windowsciliumnetworkingfunc.ps1Notes
reg.exe importcall inconfigfunc.ps1was already inside atry/catchbut the catch was unreachable for native command failures. The$LASTEXITCODEcheck now makes it catchable.nssm.exeblocks a check is added afterinstalland after the finalsetcall.Relates to IcM 613775405