Skip to content

Commit 538fcb4

Browse files
authored
use native containerd logging to file (#547)
1 parent d6234f2 commit 538fcb4

File tree

6 files changed

+192
-234
lines changed

6 files changed

+192
-234
lines changed

capz/templates/gmsa-ci.yaml

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,46 +66,39 @@ spec:
6666
}
6767
Write-Output "Extracting new containerd binaries"
6868
tar.exe -zxvf c:/k/containerd.tar.gz -C "c:/Program Files/containerd" --strip-components 1
69-
# Check if kube-log-runner.exe exists
70-
$kubeloggerPath = Join-Path $env:SYSTEMDRIVE "k\kube-log-runner.exe"
71-
if ($kubeloggerPath -and (Test-Path -Path $kubeloggerPath)) {
72-
Write-Output "Recreating containerd service with kube-log-runner..."
73-
$logPath = "\var\log\containerd"
74-
# Check if directory exists
75-
if (-Not (Test-Path -Path $logPath -PathType Container)) {
76-
Write-Host "Creating log directory: $logPath"
77-
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
78-
} else {
79-
Write-Host "Log directory already exists: $logPath"
80-
}
81-
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
82-
Write-Output "Containerd command line: $ContainerdCommandLine"
83-
# Stop and delete the existing containerd service
84-
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
85-
$null = sc.exe delete containerd
86-
# Wait for service to be fully deleted
87-
$serviceCreated = $false
88-
for ($i = 0; $i -lt 20; $i++) {
89-
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
90-
if ($null -eq $service) {
91-
Write-Host "containerd service deleted successfully, recreating with kubelogger"
92-
cmd.exe /c $ContainerdCommandLine
93-
Start-Service Containerd
94-
Write-Output "Successfully started containerd service with kubelogger"
95-
$serviceCreated = $true
96-
break
97-
}
98-
else {
99-
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
100-
}
101-
Start-Sleep -Seconds 1
102-
}
103-
if (-not $serviceCreated) {
104-
Write-Error "Failed to delete containerd service after 20 attempts"
105-
}
69+
# Recreate containerd service with native file logging
70+
Write-Output "Recreating containerd service with native file logging..."
71+
$logPath = "\var\log\containerd"
72+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
73+
Write-Host "Creating log directory: $logPath"
74+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
10675
} else {
107-
Write-Output "Starting containerd service without kube-log-runner..."
108-
Start-Service containerd
76+
Write-Host "Log directory already exists: $logPath"
77+
}
78+
$ContainerdCommandLine = '"c:\Program Files\containerd\containerd.exe" --register-service --log-file=c:\var\log\containerd\containerd.log'
79+
Write-Output "Containerd command line: $ContainerdCommandLine"
80+
# Stop and delete the existing containerd service
81+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
82+
$null = sc.exe delete containerd
83+
# Wait for service to be fully deleted
84+
$serviceCreated = $false
85+
for ($i = 0; $i -lt 20; $i++) {
86+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
87+
if ($null -eq $service) {
88+
Write-Host "containerd service deleted successfully, recreating with native file logging"
89+
cmd.exe /c $ContainerdCommandLine
90+
Start-Service Containerd
91+
Write-Output "Successfully started containerd service with native file logging"
92+
$serviceCreated = $true
93+
break
94+
}
95+
else {
96+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
97+
}
98+
Start-Sleep -Seconds 1
99+
}
100+
if (-not $serviceCreated) {
101+
Write-Error "Failed to delete containerd service after 20 attempts"
109102
}
110103
}
111104
containerd.exe --version

capz/templates/gmsa-pr.yaml

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,46 +66,39 @@ spec:
6666
}
6767
Write-Output "Extracting new containerd binaries"
6868
tar.exe -zxvf c:/k/containerd.tar.gz -C "c:/Program Files/containerd" --strip-components 1
69-
# Check if kube-log-runner.exe exists
70-
$kubeloggerPath = Join-Path $env:SYSTEMDRIVE "k\kube-log-runner.exe"
71-
if ($kubeloggerPath -and (Test-Path -Path $kubeloggerPath)) {
72-
Write-Output "Recreating containerd service with kube-log-runner..."
73-
$logPath = "\var\log\containerd"
74-
# Check if directory exists
75-
if (-Not (Test-Path -Path $logPath -PathType Container)) {
76-
Write-Host "Creating log directory: $logPath"
77-
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
78-
} else {
79-
Write-Host "Log directory already exists: $logPath"
80-
}
81-
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
82-
Write-Output "Containerd command line: $ContainerdCommandLine"
83-
# Stop and delete the existing containerd service
84-
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
85-
$null = sc.exe delete containerd
86-
# Wait for service to be fully deleted
87-
$serviceCreated = $false
88-
for ($i = 0; $i -lt 20; $i++) {
89-
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
90-
if ($null -eq $service) {
91-
Write-Host "containerd service deleted successfully, recreating with kubelogger"
92-
cmd.exe /c $ContainerdCommandLine
93-
Start-Service Containerd
94-
Write-Output "Successfully started containerd service with kubelogger"
95-
$serviceCreated = $true
96-
break
97-
}
98-
else {
99-
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
100-
}
101-
Start-Sleep -Seconds 1
102-
}
103-
if (-not $serviceCreated) {
104-
Write-Error "Failed to delete containerd service after 20 attempts"
105-
}
69+
# Recreate containerd service with native file logging
70+
Write-Output "Recreating containerd service with native file logging..."
71+
$logPath = "\var\log\containerd"
72+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
73+
Write-Host "Creating log directory: $logPath"
74+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
10675
} else {
107-
Write-Output "Starting containerd service without kube-log-runner..."
108-
Start-Service containerd
76+
Write-Host "Log directory already exists: $logPath"
77+
}
78+
$ContainerdCommandLine = '"c:\Program Files\containerd\containerd.exe" --register-service --log-file=c:\var\log\containerd\containerd.log'
79+
Write-Output "Containerd command line: $ContainerdCommandLine"
80+
# Stop and delete the existing containerd service
81+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
82+
$null = sc.exe delete containerd
83+
# Wait for service to be fully deleted
84+
$serviceCreated = $false
85+
for ($i = 0; $i -lt 20; $i++) {
86+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
87+
if ($null -eq $service) {
88+
Write-Host "containerd service deleted successfully, recreating with native file logging"
89+
cmd.exe /c $ContainerdCommandLine
90+
Start-Service Containerd
91+
Write-Output "Successfully started containerd service with native file logging"
92+
$serviceCreated = $true
93+
break
94+
}
95+
else {
96+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
97+
}
98+
Start-Sleep -Seconds 1
99+
}
100+
if (-not $serviceCreated) {
101+
Write-Error "Failed to delete containerd service after 20 attempts"
109102
}
110103
}
111104
containerd.exe --version

capz/templates/shared-image-gallery-ci.yaml

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,46 +66,39 @@ spec:
6666
}
6767
Write-Output "Extracting new containerd binaries"
6868
tar.exe -zxvf c:/k/containerd.tar.gz -C "c:/Program Files/containerd" --strip-components 1
69-
# Check if kube-log-runner.exe exists
70-
$kubeloggerPath = Join-Path $env:SYSTEMDRIVE "k\kube-log-runner.exe"
71-
if ($kubeloggerPath -and (Test-Path -Path $kubeloggerPath)) {
72-
Write-Output "Recreating containerd service with kube-log-runner..."
73-
$logPath = "\var\log\containerd"
74-
# Check if directory exists
75-
if (-Not (Test-Path -Path $logPath -PathType Container)) {
76-
Write-Host "Creating log directory: $logPath"
77-
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
78-
} else {
79-
Write-Host "Log directory already exists: $logPath"
80-
}
81-
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
82-
Write-Output "Containerd command line: $ContainerdCommandLine"
83-
# Stop and delete the existing containerd service
84-
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
85-
$null = sc.exe delete containerd
86-
# Wait for service to be fully deleted
87-
$serviceCreated = $false
88-
for ($i = 0; $i -lt 20; $i++) {
89-
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
90-
if ($null -eq $service) {
91-
Write-Host "containerd service deleted successfully, recreating with kubelogger"
92-
cmd.exe /c $ContainerdCommandLine
93-
Start-Service Containerd
94-
Write-Output "Successfully started containerd service with kubelogger"
95-
$serviceCreated = $true
96-
break
97-
}
98-
else {
99-
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
100-
}
101-
Start-Sleep -Seconds 1
102-
}
103-
if (-not $serviceCreated) {
104-
Write-Error "Failed to delete containerd service after 20 attempts"
105-
}
69+
# Recreate containerd service with native file logging
70+
Write-Output "Recreating containerd service with native file logging..."
71+
$logPath = "\var\log\containerd"
72+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
73+
Write-Host "Creating log directory: $logPath"
74+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
10675
} else {
107-
Write-Output "Starting containerd service without kube-log-runner..."
108-
Start-Service containerd
76+
Write-Host "Log directory already exists: $logPath"
77+
}
78+
$ContainerdCommandLine = '"c:\Program Files\containerd\containerd.exe" --register-service --log-file=c:\var\log\containerd\containerd.log'
79+
Write-Output "Containerd command line: $ContainerdCommandLine"
80+
# Stop and delete the existing containerd service
81+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
82+
$null = sc.exe delete containerd
83+
# Wait for service to be fully deleted
84+
$serviceCreated = $false
85+
for ($i = 0; $i -lt 20; $i++) {
86+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
87+
if ($null -eq $service) {
88+
Write-Host "containerd service deleted successfully, recreating with native file logging"
89+
cmd.exe /c $ContainerdCommandLine
90+
Start-Service Containerd
91+
Write-Output "Successfully started containerd service with native file logging"
92+
$serviceCreated = $true
93+
break
94+
}
95+
else {
96+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
97+
}
98+
Start-Sleep -Seconds 1
99+
}
100+
if (-not $serviceCreated) {
101+
Write-Error "Failed to delete containerd service after 20 attempts"
109102
}
110103
}
111104
containerd.exe --version

capz/templates/windows-base.yaml

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,46 +66,39 @@ spec:
6666
}
6767
Write-Output "Extracting new containerd binaries"
6868
tar.exe -zxvf c:/k/containerd.tar.gz -C "c:/Program Files/containerd" --strip-components 1
69-
# Check if kube-log-runner.exe exists
70-
$kubeloggerPath = Join-Path $env:SYSTEMDRIVE "k\kube-log-runner.exe"
71-
if ($kubeloggerPath -and (Test-Path -Path $kubeloggerPath)) {
72-
Write-Output "Recreating containerd service with kube-log-runner..."
73-
$logPath = "\var\log\containerd"
74-
# Check if directory exists
75-
if (-Not (Test-Path -Path $logPath -PathType Container)) {
76-
Write-Host "Creating log directory: $logPath"
77-
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
78-
} else {
79-
Write-Host "Log directory already exists: $logPath"
80-
}
81-
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
82-
Write-Output "Containerd command line: $ContainerdCommandLine"
83-
# Stop and delete the existing containerd service
84-
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
85-
$null = sc.exe delete containerd
86-
# Wait for service to be fully deleted
87-
$serviceCreated = $false
88-
for ($i = 0; $i -lt 20; $i++) {
89-
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
90-
if ($null -eq $service) {
91-
Write-Host "containerd service deleted successfully, recreating with kubelogger"
92-
cmd.exe /c $ContainerdCommandLine
93-
Start-Service Containerd
94-
Write-Output "Successfully started containerd service with kubelogger"
95-
$serviceCreated = $true
96-
break
97-
}
98-
else {
99-
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
100-
}
101-
Start-Sleep -Seconds 1
102-
}
103-
if (-not $serviceCreated) {
104-
Write-Error "Failed to delete containerd service after 20 attempts"
105-
}
69+
# Recreate containerd service with native file logging
70+
Write-Output "Recreating containerd service with native file logging..."
71+
$logPath = "\var\log\containerd"
72+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
73+
Write-Host "Creating log directory: $logPath"
74+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
10675
} else {
107-
Write-Output "Starting containerd service without kube-log-runner..."
108-
Start-Service containerd
76+
Write-Host "Log directory already exists: $logPath"
77+
}
78+
$ContainerdCommandLine = '"c:\Program Files\containerd\containerd.exe" --register-service --log-file=c:\var\log\containerd\containerd.log'
79+
Write-Output "Containerd command line: $ContainerdCommandLine"
80+
# Stop and delete the existing containerd service
81+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
82+
$null = sc.exe delete containerd
83+
# Wait for service to be fully deleted
84+
$serviceCreated = $false
85+
for ($i = 0; $i -lt 20; $i++) {
86+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
87+
if ($null -eq $service) {
88+
Write-Host "containerd service deleted successfully, recreating with native file logging"
89+
cmd.exe /c $ContainerdCommandLine
90+
Start-Service Containerd
91+
Write-Output "Successfully started containerd service with native file logging"
92+
$serviceCreated = $true
93+
break
94+
}
95+
else {
96+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
97+
}
98+
Start-Sleep -Seconds 1
99+
}
100+
if (-not $serviceCreated) {
101+
Write-Error "Failed to delete containerd service after 20 attempts"
109102
}
110103
}
111104
containerd.exe --version

0 commit comments

Comments
 (0)