GCE Windows: add 20H2; install docker when nodes are started

This commit is contained in:
Peter Hornyack 2021-01-21 16:19:51 -08:00
parent 661eae7c7c
commit 21592c23e1
3 changed files with 66 additions and 4 deletions

View File

@ -88,11 +88,13 @@ function set-linux-node-image() {
function set-windows-node-image() {
WINDOWS_NODE_IMAGE_PROJECT="windows-cloud"
if [[ "${WINDOWS_NODE_OS_DISTRIBUTION}" == "win2019" ]]; then
WINDOWS_NODE_IMAGE="windows-server-2019-dc-core-for-containers-v20200908"
WINDOWS_NODE_IMAGE="windows-server-2019-dc-core-v20210112"
elif [[ "${WINDOWS_NODE_OS_DISTRIBUTION}" == "win1909" ]]; then
WINDOWS_NODE_IMAGE="windows-server-1909-dc-core-for-containers-v20200908"
elif [[ "${WINDOWS_NODE_OS_DISTRIBUTION}" == "win1809" ]]; then
WINDOWS_NODE_IMAGE="windows-server-1809-dc-core-for-containers-v20200908"
WINDOWS_NODE_IMAGE="windows-server-1909-dc-core-v20210112"
elif [[ "${WINDOWS_NODE_OS_DISTRIBUTION}" == "win2004" ]]; then
WINDOWS_NODE_IMAGE="windows-server-2004-dc-core-v20210112"
elif [[ "${WINDOWS_NODE_OS_DISTRIBUTION,,}" == "win20h2" ]]; then
WINDOWS_NODE_IMAGE="windows-server-20h2-dc-core-v20210112"
else
echo "Unknown WINDOWS_NODE_OS_DISTRIBUTION ${WINDOWS_NODE_OS_DISTRIBUTION}" >&2
exit 1

View File

@ -117,6 +117,26 @@ try {
FetchAndImport-ModuleFromMetadata 'k8s-node-setup-psm1' 'k8s-node-setup.psm1'
Dump-DebugInfoToConsole
if (-not (Test-ContainersFeatureInstalled)) {
Install-ContainersFeature
Log-Output 'Restarting computer after enabling Windows Containers feature'
Restart-Computer -Force
# Restart-Computer does not stop the rest of the script from executing.
exit 0
}
if (-not (Test-DockerIsInstalled)) {
Install-Docker
}
# For some reason the docker service may not be started automatically on the
# first reboot, although it seems to work fine on subsequent reboots.
Restart-Service docker
Start-Sleep 5
if (-not (Test-DockerIsRunning)) {
throw "docker service failed to start or stay running"
}
Set-PrerequisiteOptions
$kube_env = Fetch-KubeEnv

View File

@ -1321,6 +1321,46 @@ function Setup-ContainerRuntime {
}
}
function Test-ContainersFeatureInstalled {
return (Get-WindowsFeature Containers).Installed
}
# After this function returns, the computer must be restarted to complete
# the installation!
function Install-ContainersFeature {
Log-Output "Installing Windows 'Containers' feature"
Install-WindowsFeature Containers
}
function Test-DockerIsInstalled {
return ((Get-Package `
-ProviderName DockerMsftProvider `
-ErrorAction SilentlyContinue |
Where-Object Name -eq 'docker') -ne $null)
}
function Test-DockerIsRunning {
return ((Get-Service docker).Status -eq 'Running')
}
# Installs Docker EE via the DockerMsftProvider. Ensure that the Windows
# Containers feature is installed before calling this function; otherwise,
# a restart may be needed after this function returns.
function Install-Docker {
Log-Output 'Installing NuGet module'
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Log-Output 'Installing DockerMsftProvider module'
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Log-Output "Installing latest Docker EE version"
Install-Package `
-Name docker `
-ProviderName DockerMsftProvider `
-Force `
-Verbose
}
# Add a registry key for docker in EventLog so that log messages are mapped
# correctly. This is a workaround since the key is missing in the base image.
# https://github.com/MicrosoftDocs/Virtualization-Documentation/pull/503