diff --git a/cluster/gce/config-default.sh b/cluster/gce/config-default.sh index a94179a783e..fc9ccde1670 100755 --- a/cluster/gce/config-default.sh +++ b/cluster/gce/config-default.sh @@ -560,6 +560,10 @@ export WINDOWS_ENABLE_DSR="${WINDOWS_ENABLE_DSR:-false}" export WINDOWS_ENABLE_NODE_PROBLEM_DETECTOR="${WINDOWS_ENABLE_NODE_PROBLEM_DETECTOR:-none}" export WINDOWS_NODE_PROBLEM_DETECTOR_CUSTOM_FLAGS="${WINDOWS_NODE_PROBLEM_DETECTOR_CUSTOM_FLAGS:-}" +# Enable Windows Hyper-V +# sig-storage uses it to create Virtual Hard Disks in tests +export WINDOWS_ENABLE_HYPERV="${WINDOWS_ENABLE_HYPERV:-false}" + # TLS_CIPHER_SUITES defines cipher suites allowed to be used by kube-apiserver. # If this variable is unset or empty, kube-apiserver will allow its default set of cipher suites. export TLS_CIPHER_SUITES="" diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 093fcdbfec9..8cc89894f06 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -1602,6 +1602,7 @@ BOOTSTRAP_KUBECONFIG_FILE: $(yaml-quote "${WINDOWS_BOOTSTRAP_KUBECONFIG_FILE}") KUBEPROXY_KUBECONFIG_FILE: $(yaml-quote "${WINDOWS_KUBEPROXY_KUBECONFIG_FILE}") WINDOWS_INFRA_CONTAINER: $(yaml-quote "${WINDOWS_INFRA_CONTAINER}") WINDOWS_ENABLE_PIGZ: $(yaml-quote "${WINDOWS_ENABLE_PIGZ}") +WINDOWS_ENABLE_HYPERV: $(yaml-quote "${WINDOWS_ENABLE_HYPERV}") ENABLE_NODE_PROBLEM_DETECTOR: $(yaml-quote "${WINDOWS_ENABLE_NODE_PROBLEM_DETECTOR}") NODE_PROBLEM_DETECTOR_VERSION: $(yaml-quote "${NODE_PROBLEM_DETECTOR_VERSION}") NODE_PROBLEM_DETECTOR_TAR_HASH: $(yaml-quote "${NODE_PROBLEM_DETECTOR_TAR_HASH}") diff --git a/cluster/gce/windows/configure.ps1 b/cluster/gce/windows/configure.ps1 index 8f8453e121c..c2623bcc972 100644 --- a/cluster/gce/windows/configure.ps1 +++ b/cluster/gce/windows/configure.ps1 @@ -118,17 +118,32 @@ try { Dump-DebugInfoToConsole + $kube_env = Fetch-KubeEnv + Set-EnvironmentVars + + # Set to true if there's a feature that needs a reboot + $restart_computer = $false + + $should_enable_hyperv = Test-ShouldEnableHyperVFeature + $hyperv_feature_enabled = Test-HyperVFeatureEnabled + if ($should_enable_hyperv -and -not ($hyperv_feature_enabled)) { + Enable-HyperVFeature + Log-Output 'Restarting computer after enabling Windows Hyper-V feature' + $restart_computer = $true + } + if (-not (Test-ContainersFeatureInstalled)) { Install-ContainersFeature Log-Output 'Restarting computer after enabling Windows Containers feature' + $restart_computer = $true + } + + if ($restart_computer) { Restart-Computer -Force # Restart-Computer does not stop the rest of the script from executing. exit 0 } - $kube_env = Fetch-KubeEnv - Set-EnvironmentVars - # Set the TCP/IP Parameters to keep idle connections alive. Set-WindowsTCPParameters diff --git a/cluster/gce/windows/k8s-node-setup.psm1 b/cluster/gce/windows/k8s-node-setup.psm1 index c0e3dae1b14..4a6aa7d7d90 100644 --- a/cluster/gce/windows/k8s-node-setup.psm1 +++ b/cluster/gce/windows/k8s-node-setup.psm1 @@ -295,6 +295,7 @@ function Set-EnvironmentVars { "MANIFESTS_DIR" = ${kube_env}['MANIFESTS_DIR'] "INFRA_CONTAINER" = ${kube_env}['WINDOWS_INFRA_CONTAINER'] "WINDOWS_ENABLE_PIGZ" = ${kube_env}['WINDOWS_ENABLE_PIGZ'] + "WINDOWS_ENABLE_HYPERV" = ${kube_env}['WINDOWS_ENABLE_HYPERV'] "ENABLE_NODE_PROBLEM_DETECTOR" = ${kube_env}['ENABLE_NODE_PROBLEM_DETECTOR'] "NODEPROBLEMDETECTOR_KUBECONFIG_FILE" = ${kube_env}['WINDOWS_NODEPROBLEMDETECTOR_KUBECONFIG_FILE'] @@ -1386,6 +1387,24 @@ function Install-ContainersFeature { Install-WindowsFeature Containers } +# Verifies if Hyper-V should be enabled in the node +function Test-ShouldEnableHyperVFeature { + return "${env:WINDOWS_ENABLE_HYPERV}" -eq "true" +} + +# Check if Hyper-V feature is enabled +function Test-HyperVFeatureEnabled { + return ((Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V).State -eq 'Enabled') +} + +# After this function returns, the computer must be restarted to complete +# the installation! +function Enable-HyperVFeature { + Log-Output "Enabling Windows 'HyperV' feature" + Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart + Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell -All -NoRestart +} + function Test-DockerIsInstalled { return ((Get-Package ` -ProviderName DockerMsftProvider `