-
Notifications
You must be signed in to change notification settings - Fork 247
fix: better error message in windows CSE when API server can't be contacted #7828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -182,6 +182,7 @@ function Check-APIServerConnectivity { | |||||||||||||||||
| ) | ||||||||||||||||||
| Logs-To-Event -TaskName "AKS.WindowsCSE.CheckAPIServerConnectivity" -TaskMessage "Start to check API server connectivity." | ||||||||||||||||||
| $retryCount=0 | ||||||||||||||||||
| $LastException=$null | ||||||||||||||||||
|
|
||||||||||||||||||
| do { | ||||||||||||||||||
| $retryString="${retryCount}/${MaxRetryCount}" | ||||||||||||||||||
|
|
@@ -201,17 +202,30 @@ function Check-APIServerConnectivity { | |||||||||||||||||
| } | ||||||||||||||||||
| $tcpClient.Close() | ||||||||||||||||||
| } catch [System.AggregateException] { | ||||||||||||||||||
| Write-Log "Retry ${retryString}: Failed to connect to API server $MasterIP. AggregateException: " + $_.Exception.ToString() | ||||||||||||||||||
| Logs-To-Event -TaskName "AKS.WindowsCSE.CheckAPIServerConnectivity" -TaskMessage "Retry ${retryString}: Failed to connect to API server $MasterIP. AggregateException: " + $_.Exception.ToString() | ||||||||||||||||||
| $LastException = $_.Exception.ToString() | ||||||||||||||||||
| } catch { | ||||||||||||||||||
| Write-Log "Retry ${retryString}: Failed to connect to API server $MasterIP. Error: $_" | ||||||||||||||||||
| } | ||||||||||||||||||
| Logs-To-Event -TaskName "AKS.WindowsCSE.CheckAPIServerConnectivity" -TaskMessage "Retry ${retryString}: Failed to connect to API server $MasterIP. Error: $_" | ||||||||||||||||||
| $LastException = "$_" | ||||||||||||||||||
timmy-wright marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| $retryCount++ | ||||||||||||||||||
| Write-Log "Retry ${retryString}: Sleep $RetryInterval and then retry to connect to API server" | ||||||||||||||||||
| Sleep $RetryInterval | ||||||||||||||||||
| } while ($retryCount -lt $MaxRetryCount) | ||||||||||||||||||
|
|
||||||||||||||||||
| Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_CHECK_API_SERVER_CONNECTIVITY -ErrorMessage "Failed to connect to API server $MasterIP after $retryCount retries" | ||||||||||||||||||
| $lastExceptionMessage = "" | ||||||||||||||||||
| if ($LastException -ne $null) { | ||||||||||||||||||
| if ($LastException.Exception -ne $null -and -not [string]::IsNullOrEmpty($LastException.Exception.Message)) { | ||||||||||||||||||
| $lastExceptionMessage = $LastException.Exception.Message | ||||||||||||||||||
| } else { | ||||||||||||||||||
|
Comment on lines
+217
to
+221
|
||||||||||||||||||
| $lastExceptionMessage = $LastException.ToString() | ||||||||||||||||||
| } | ||||||||||||||||||
| # Normalize any CR/LF in the exception message to spaces to keep ErrorMessage single-line. | ||||||||||||||||||
| $lastExceptionMessage = $lastExceptionMessage -replace "(`r|`n)+", " " | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_CHECK_API_SERVER_CONNECTIVITY -ErrorMessage "Failed to connect to API server $MasterIP after $retryCount retries. Last exception: $lastExceptionMessage" | ||||||||||||||||||
|
||||||||||||||||||
| Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_CHECK_API_SERVER_CONNECTIVITY -ErrorMessage "Failed to connect to API server $MasterIP after $retryCount retries. Last exception: $lastExceptionMessage" | |
| $baseErrorMessage = "Failed to connect to API server $MasterIP after $retryCount retries." | |
| $errorMessage = $baseErrorMessage | |
| if (-not [string]::IsNullOrEmpty($lastExceptionMessage)) { | |
| $errorMessage = "$baseErrorMessage Last exception: $lastExceptionMessage" | |
| } | |
| Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_CHECK_API_SERVER_CONNECTIVITY -ErrorMessage $errorMessage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logs-To-Event -TaskMessage "..." + $_.Exception.ToString()is likely to be parsed in argument mode as multiple arguments ("...", '+', and the exception string), which can break parameter binding at runtime. Wrap the concatenation in parentheses or use a single interpolated string/subexpression so-TaskMessagereceives one string value.