Skip to content

Commit

Permalink
feat: support Windows container local dumps (#3684)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelHu authored Feb 23, 2024
1 parent c3446ed commit 166558d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
10 changes: 10 additions & 0 deletions parts/windows/windowscsehelper.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ Describe 'Install-Containerd-Based-On-Kubernetes-Version' {
Assert-MockCalled -CommandName "Install-Containerd" -Exactly -Times 1 -ParameterFilter { $ContainerdUrl -eq $expectedURL }
}

# It retrieves the containerd version from containerd URL in Install-Containerd in staging/cse/windows/containerdfunc.ps1
It 'validate whether containerd URL has the correct version' {
$fileName = [IO.Path]::GetFileName($global:StableContainerdPackage)
$containerdVersion = $fileName.Split("-")[1].SubString(1)
{Write-Host ([version]$containerdVersion)} | Should -Not -Throw

$fileName = [IO.Path]::GetFileName($global:LatestContainerdPackage)
$containerdVersion = $fileName.Split("-")[1].SubString(1)
{Write-Host ([version]$containerdVersion)} | Should -Not -Throw
}
}

Describe 'Get-WindowsVersion and Get-WindowsPauseVersion' {
Expand Down
24 changes: 21 additions & 3 deletions staging/cse/windows/containerdfunc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ function Install-Containerd {
}

# TODO: check if containerd is already installed and is the same version before this.


$fileName = [IO.Path]::GetFileName($ContainerdUrl)
$containerdVersion = $fileName.Split("-")[1].SubString(1) # not full version, just the version number. For example, 1.7.9. The full version is v1.7.9-azure.1

# Extract the package
# upstream containerd package is a tar
$tarfile = [Io.path]::Combine($ENV:TEMP, "containerd.tar.gz")
Expand All @@ -161,6 +164,8 @@ function Install-Containerd {
$windowsVersion = Get-WindowsPauseVersion
$hypervRuntimes = ""
$hypervHandlers = $global:ContainerdWindowsRuntimeHandlers.split(",", [System.StringSplitOptions]::RemoveEmptyEntries)
$containerAnnotations = 'container_annotations = ["io.microsoft.container.processdumplocation", "io.microsoft.wcow.processdumptype", "io.microsoft.wcow.processdumpcount"]'
$podAnnotations = 'pod_annotations = ["io.microsoft.container.processdumplocation","io.microsoft.wcow.processdumptype", "io.microsoft.wcow.processdumpcount"]'

# configure
if ($global:DefaultContainerdWindowsSandboxIsolation -eq "hyperv") {
Expand All @@ -171,18 +176,31 @@ function Install-Containerd {
$template = Get-Content -Path "c:\AzureData\windows\containerdtemplate.toml"
if ($sandboxIsolation -eq 0 -And $hypervHandlers.Count -eq 0) {
# remove the value hypervisor place holder
$template = $template | Select-String -Pattern 'hypervisors' -NotMatch | Out-String
$template = $template | Select-String -Pattern 'hypervisors' -NotMatch
}
else {
$hypervRuntimes = CreateHypervisorRuntimes -builds @($hypervHandlers) -image $pauseImage
}

# remove the value containerAnnotations and podAnnotations place holder since it is not supported in containerd versions older than 1.7.9
if (([version]$containerdVersion).CompareTo([version]"1.7.9") -lt 0) {
# remove the value containerAnnotations place holder
$template = $template | Select-String -Pattern 'containerAnnotations' -NotMatch
# remove the value podAnnotations place holder
$template = $template | Select-String -Pattern 'podAnnotations' -NotMatch
}

# Need to convert the template to string to replace the place holders but
# `Select-String -Pattern [PATTERN] -NotMatch` does not work after converting the template to string
$template = $template | Out-String
$template.Replace('{{sandboxIsolation}}', $sandboxIsolation).
Replace('{{pauseImage}}', $pauseImage).
Replace('{{hypervisors}}', $hypervRuntimes).
Replace('{{cnibin}}', $formatedbin).
Replace('{{cniconf}}', $formatedconf).
Replace('{{currentversion}}', $windowsVersion) | `
Replace('{{currentversion}}', $windowsVersion).
Replace('{{containerAnnotations}}', $containerAnnotations).
Replace('{{podAnnotations}}', $podAnnotations) | `
Out-File -FilePath "$configFile" -Encoding ascii

RegisterContainerDService -KubeDir $KubeDir
Expand Down
4 changes: 4 additions & 0 deletions staging/cse/windows/containerdtemplate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ state = "C:\\ProgramData\\containerd\\state"
no_pivot = false
[plugins.cri.containerd.default_runtime]
runtime_type = "io.containerd.runhcs.v1"
{{containerAnnotations}}
{{podAnnotations}}
[plugins.cri.containerd.default_runtime.options]
Debug = false
DebugType = 0
Expand All @@ -46,6 +48,8 @@ state = "C:\\ProgramData\\containerd\\state"
[plugins.cri.containerd.runtimes]
[plugins.cri.containerd.runtimes.runhcs-wcow-process]
runtime_type = "io.containerd.runhcs.v1"
{{containerAnnotations}}
{{podAnnotations}}
[plugins.cri.containerd.runtimes.runhcs-wcow-process.options]
Debug = true
DebugType = 2
Expand Down

0 comments on commit 166558d

Please sign in to comment.