Skip to content

Commit 793e410

Browse files
committed
Make ContainerD logs to file
1 parent cf86a39 commit 793e410

File tree

7 files changed

+244
-14
lines changed

7 files changed

+244
-14
lines changed

capz/run-capz-e2e.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ main() {
3333
export CAPI_VERSION="${CAPI_VERSION:-"v1.7.2"}"
3434
export HELM_VERSION=v3.15.2
3535
export TOOLS_BIN_DIR="${TOOLS_BIN_DIR:-$SCRIPT_ROOT/tools/bin}"
36+
export CONTAINERD_LOGGER="${CONTAINERD_LOGGER:-""}"
3637

3738
# other config
3839
export ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}"
@@ -320,9 +321,10 @@ EOF
320321
kubectl apply -f "${CAPZ_DIR}"/templates/test/ci/patches/windows-kubeproxy-ci.yaml
321322
kubectl rollout restart ds -n kube-system kube-proxy-windows
322323
fi
323-
324324
# apply additional helper manifests (logger etc)
325-
kubectl apply -f "${CAPZ_DIR}"/templates/addons/windows/containerd-logging/containerd-logger.yaml
325+
if [[ -n "$CONTAINERD_LOGGER" ]]; then
326+
kubectl apply -f "${CAPZ_DIR}"/templates/addons/windows/containerd-logging/containerd-logger.yaml
327+
fi
326328
kubectl apply -f "${CAPZ_DIR}"/templates/addons/windows/csi-proxy/csi-proxy.yaml
327329
kubectl apply -f "${CAPZ_DIR}"/templates/addons/metrics-server/metrics-server.yaml
328330
}

capz/templates/gmsa-ci.yaml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,46 @@ 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-
70-
Start-Service containerd
69+
# Check if kube-log-runner.exe exists
70+
if (Test-Path $kubeloggerPath) {
71+
Write-Output "Recreating containerd service with kube-log-runner..."
72+
$logPath = "\var\log\containerd"
73+
# Check if directory exists
74+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
75+
Write-Host "Creating log directory: $logPath"
76+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
77+
} else {
78+
Write-Host "Log directory already exists: $logPath"
79+
}
80+
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
81+
Write-Output "Containerd command line: $ContainerdCommandLine"
82+
# Stop and delete the existing containerd service
83+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
84+
$null = sc.exe delete containerd
85+
# Wait for service to be fully deleted
86+
$serviceCreated = $false
87+
for ($i = 0; $i -lt 20; $i++) {
88+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
89+
if ($null -eq $service) {
90+
Write-Host "containerd service deleted successfully, recreating with kubelogger"
91+
cmd.exe /c $ContainerdCommandLine
92+
Start-Service Containerd
93+
Write-Output "Successfully started containerd service with kubelogger"
94+
$serviceCreated = $true
95+
break
96+
}
97+
else {
98+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
99+
}
100+
Start-Sleep -Seconds 1
101+
}
102+
if (-not $serviceCreated) {
103+
Write-Error "Failed to delete containerd service after 20 attempts"
104+
}
105+
} else {
106+
Write-Output "Starting containerd service without kube-log-runner..."
107+
Start-Service containerd
108+
}
71109
}
72110
containerd.exe --version
73111
containerd-shim-runhcs-v1.exe --version

capz/templates/gmsa-pr.yaml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,46 @@ 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-
70-
Start-Service containerd
69+
# Check if kube-log-runner.exe exists
70+
if (Test-Path $kubeloggerPath) {
71+
Write-Output "Recreating containerd service with kube-log-runner..."
72+
$logPath = "\var\log\containerd"
73+
# Check if directory exists
74+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
75+
Write-Host "Creating log directory: $logPath"
76+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
77+
} else {
78+
Write-Host "Log directory already exists: $logPath"
79+
}
80+
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
81+
Write-Output "Containerd command line: $ContainerdCommandLine"
82+
# Stop and delete the existing containerd service
83+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
84+
$null = sc.exe delete containerd
85+
# Wait for service to be fully deleted
86+
$serviceCreated = $false
87+
for ($i = 0; $i -lt 20; $i++) {
88+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
89+
if ($null -eq $service) {
90+
Write-Host "containerd service deleted successfully, recreating with kubelogger"
91+
cmd.exe /c $ContainerdCommandLine
92+
Start-Service Containerd
93+
Write-Output "Successfully started containerd service with kubelogger"
94+
$serviceCreated = $true
95+
break
96+
}
97+
else {
98+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
99+
}
100+
Start-Sleep -Seconds 1
101+
}
102+
if (-not $serviceCreated) {
103+
Write-Error "Failed to delete containerd service after 20 attempts"
104+
}
105+
} else {
106+
Write-Output "Starting containerd service without kube-log-runner..."
107+
Start-Service containerd
108+
}
71109
}
72110
containerd.exe --version
73111
containerd-shim-runhcs-v1.exe --version

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,46 @@ 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-
70-
Start-Service containerd
69+
# Check if kube-log-runner.exe exists
70+
if (Test-Path $kubeloggerPath) {
71+
Write-Output "Recreating containerd service with kube-log-runner..."
72+
$logPath = "\var\log\containerd"
73+
# Check if directory exists
74+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
75+
Write-Host "Creating log directory: $logPath"
76+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
77+
} else {
78+
Write-Host "Log directory already exists: $logPath"
79+
}
80+
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
81+
Write-Output "Containerd command line: $ContainerdCommandLine"
82+
# Stop and delete the existing containerd service
83+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
84+
$null = sc.exe delete containerd
85+
# Wait for service to be fully deleted
86+
$serviceCreated = $false
87+
for ($i = 0; $i -lt 20; $i++) {
88+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
89+
if ($null -eq $service) {
90+
Write-Host "containerd service deleted successfully, recreating with kubelogger"
91+
cmd.exe /c $ContainerdCommandLine
92+
Start-Service Containerd
93+
Write-Output "Successfully started containerd service with kubelogger"
94+
$serviceCreated = $true
95+
break
96+
}
97+
else {
98+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
99+
}
100+
Start-Sleep -Seconds 1
101+
}
102+
if (-not $serviceCreated) {
103+
Write-Error "Failed to delete containerd service after 20 attempts"
104+
}
105+
} else {
106+
Write-Output "Starting containerd service without kube-log-runner..."
107+
Start-Service containerd
108+
}
71109
}
72110
containerd.exe --version
73111
containerd-shim-runhcs-v1.exe --version

capz/templates/windows-base.yaml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,46 @@ 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-
70-
Start-Service containerd
69+
# Check if kube-log-runner.exe exists
70+
if (Test-Path $kubeloggerPath) {
71+
Write-Output "Recreating containerd service with kube-log-runner..."
72+
$logPath = "\var\log\containerd"
73+
# Check if directory exists
74+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
75+
Write-Host "Creating log directory: $logPath"
76+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
77+
} else {
78+
Write-Host "Log directory already exists: $logPath"
79+
}
80+
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
81+
Write-Output "Containerd command line: $ContainerdCommandLine"
82+
# Stop and delete the existing containerd service
83+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
84+
$null = sc.exe delete containerd
85+
# Wait for service to be fully deleted
86+
$serviceCreated = $false
87+
for ($i = 0; $i -lt 20; $i++) {
88+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
89+
if ($null -eq $service) {
90+
Write-Host "containerd service deleted successfully, recreating with kubelogger"
91+
cmd.exe /c $ContainerdCommandLine
92+
Start-Service Containerd
93+
Write-Output "Successfully started containerd service with kubelogger"
94+
$serviceCreated = $true
95+
break
96+
}
97+
else {
98+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
99+
}
100+
Start-Sleep -Seconds 1
101+
}
102+
if (-not $serviceCreated) {
103+
Write-Error "Failed to delete containerd service after 20 attempts"
104+
}
105+
} else {
106+
Write-Output "Starting containerd service without kube-log-runner..."
107+
Start-Service containerd
108+
}
71109
}
72110
containerd.exe --version
73111
containerd-shim-runhcs-v1.exe --version

capz/templates/windows-ci.yaml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,46 @@ 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-
70-
Start-Service containerd
69+
# Check if kube-log-runner.exe exists
70+
if (Test-Path $kubeloggerPath) {
71+
Write-Output "Recreating containerd service with kube-log-runner..."
72+
$logPath = "\var\log\containerd"
73+
# Check if directory exists
74+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
75+
Write-Host "Creating log directory: $logPath"
76+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
77+
} else {
78+
Write-Host "Log directory already exists: $logPath"
79+
}
80+
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
81+
Write-Output "Containerd command line: $ContainerdCommandLine"
82+
# Stop and delete the existing containerd service
83+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
84+
$null = sc.exe delete containerd
85+
# Wait for service to be fully deleted
86+
$serviceCreated = $false
87+
for ($i = 0; $i -lt 20; $i++) {
88+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
89+
if ($null -eq $service) {
90+
Write-Host "containerd service deleted successfully, recreating with kubelogger"
91+
cmd.exe /c $ContainerdCommandLine
92+
Start-Service Containerd
93+
Write-Output "Successfully started containerd service with kubelogger"
94+
$serviceCreated = $true
95+
break
96+
}
97+
else {
98+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
99+
}
100+
Start-Sleep -Seconds 1
101+
}
102+
if (-not $serviceCreated) {
103+
Write-Error "Failed to delete containerd service after 20 attempts"
104+
}
105+
} else {
106+
Write-Output "Starting containerd service without kube-log-runner..."
107+
Start-Service containerd
108+
}
71109
}
72110
containerd.exe --version
73111
containerd-shim-runhcs-v1.exe --version

capz/templates/windows-pr.yaml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,46 @@ 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-
70-
Start-Service containerd
69+
# Check if kube-log-runner.exe exists
70+
if (Test-Path $kubeloggerPath) {
71+
Write-Output "Recreating containerd service with kube-log-runner..."
72+
$logPath = "\var\log\containerd"
73+
# Check if directory exists
74+
if (-Not (Test-Path -Path $logPath -PathType Container)) {
75+
Write-Host "Creating log directory: $logPath"
76+
New-Item -ItemType Directory -Path $logPath -Force | Out-Null
77+
} else {
78+
Write-Host "Log directory already exists: $logPath"
79+
}
80+
$ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service'
81+
Write-Output "Containerd command line: $ContainerdCommandLine"
82+
# Stop and delete the existing containerd service
83+
Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue
84+
$null = sc.exe delete containerd
85+
# Wait for service to be fully deleted
86+
$serviceCreated = $false
87+
for ($i = 0; $i -lt 20; $i++) {
88+
$service = Get-Service -Name containerd -ErrorAction SilentlyContinue
89+
if ($null -eq $service) {
90+
Write-Host "containerd service deleted successfully, recreating with kubelogger"
91+
cmd.exe /c $ContainerdCommandLine
92+
Start-Service Containerd
93+
Write-Output "Successfully started containerd service with kubelogger"
94+
$serviceCreated = $true
95+
break
96+
}
97+
else {
98+
Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)"
99+
}
100+
Start-Sleep -Seconds 1
101+
}
102+
if (-not $serviceCreated) {
103+
Write-Error "Failed to delete containerd service after 20 attempts"
104+
}
105+
} else {
106+
Write-Output "Starting containerd service without kube-log-runner..."
107+
Start-Service containerd
108+
}
71109
}
72110
containerd.exe --version
73111
containerd-shim-runhcs-v1.exe --version

0 commit comments

Comments
 (0)