Skip to content

Commit 6b6290c

Browse files
authored
fix: reduce windows VM provision time (#7483)
1 parent ceb0fff commit 6b6290c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

staging/cse/windows/containerdfunc.ps1

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,37 @@ function RegisterContainerDService {
3636
& "$KubeDir\nssm.exe" set containerd AppRotateBytes 10485760 | RemoveNulls
3737

3838
$retryCount=0
39-
$retryInterval=10
4039
$maxRetryCount=6 # 1 minutes
4140

4241
do {
4342
$svc = Get-Service -Name "containerd" -ErrorAction SilentlyContinue
4443
if ($null -eq $svc) {
4544
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_CONTAINERD_NOT_INSTALLED -ErrorMessage "containerd.exe did not get installed as a service correctly."
4645
}
46+
4747
if ($svc.Status -eq "Running") {
48+
Write-Log "containerd service is running"
4849
break
4950
}
50-
Write-Log "Starting containerd, current status: $svc.Status"
51-
Start-Service containerd
51+
5252
$retryCount++
53-
Write-Log "Retry $retryCount : Sleep $retryInterval and check containerd status"
54-
Start-Sleep $retryInterval
53+
Write-Log "Starting containerd service (attempt $retryCount of $maxRetryCount), current status: $($svc.Status)"
54+
55+
try {
56+
Start-Service containerd -ErrorAction Stop
57+
$svc = Get-Service -Name "containerd"
58+
$svc.WaitForStatus('Running', [timespan]::FromSeconds(5))
59+
Write-Log "containerd service started successfully"
60+
break
61+
}
62+
catch {
63+
Write-Log "Failed to start containerd service: $_"
64+
}
65+
66+
if ($retryCount -lt $maxRetryCount) {
67+
Write-Log "Retry $retryCount failed. Waiting 5 seconds before next attempt..."
68+
Start-Sleep -Seconds 5
69+
}
5570
} while ($retryCount -lt $maxRetryCount)
5671

5772
if ($svc.Status -ne "Running") {

0 commit comments

Comments
 (0)