KubeEnv var to enable Hyper-V in Windows

This commit is contained in:
Mauricio Poppe 2021-10-29 06:28:45 +00:00
parent c86aabbbab
commit 9e29cc042e
4 changed files with 42 additions and 3 deletions

View File

@ -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=""

View File

@ -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}")

View File

@ -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

View File

@ -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 `