Skip to content

Commit cbe6b64

Browse files
committed
better error
1 parent b014d2f commit cbe6b64

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

staging/cse/windows/kubernetesfunc.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function Check-APIServerConnectivity {
182182
)
183183
Logs-To-Event -TaskName "AKS.WindowsCSE.CheckAPIServerConnectivity" -TaskMessage "Start to check API server connectivity."
184184
$retryCount=0
185+
$LastException=$null
185186

186187
do {
187188
$retryString="${retryCount}/${MaxRetryCount}"
@@ -202,16 +203,18 @@ function Check-APIServerConnectivity {
202203
$tcpClient.Close()
203204
} catch [System.AggregateException] {
204205
Write-Log "Retry ${retryString}: Failed to connect to API server $MasterIP. AggregateException: " + $_.Exception.ToString()
206+
$LastException = $_.Exception.ToString()
205207
} catch {
206208
Write-Log "Retry ${retryString}: Failed to connect to API server $MasterIP. Error: $_"
207-
}
209+
$LastException = $_.ToString()
210+
}
208211

209212
$retryCount++
210213
Write-Log "Retry ${retryString}: Sleep $RetryInterval and then retry to connect to API server"
211214
Sleep $RetryInterval
212215
} while ($retryCount -lt $MaxRetryCount)
213216

214-
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_CHECK_API_SERVER_CONNECTIVITY -ErrorMessage "Failed to connect to API server $MasterIP after $retryCount retries"
217+
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_CHECK_API_SERVER_CONNECTIVITY -ErrorMessage "Failed to connect to API server $MasterIP after $retryCount retries. Last exception: $LastException"
215218
}
216219

217220
function Get-CACertificates {

0 commit comments

Comments
 (0)