mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Merge pull request #74762 from pjh/gce-windows-dump-versions
Dump Windows version information during cluster bringup.
This commit is contained in:
commit
98c0d15f98
@ -71,14 +71,13 @@ function ShouldWrite-File {
|
||||
|
||||
# Returns the GCE instance metadata value for $Key. If the key is not present
|
||||
# in the instance metadata returns $Default if set, otherwise returns $null.
|
||||
function Get-InstanceMetadataValue {
|
||||
function Get-InstanceMetadata {
|
||||
param (
|
||||
[parameter(Mandatory=$true)] [string]$Key,
|
||||
[parameter(Mandatory=$false)] [string]$Default
|
||||
)
|
||||
|
||||
$url = ("http://metadata.google.internal/computeMetadata/v1/instance/" +
|
||||
"attributes/$Key")
|
||||
$url = "http://metadata.google.internal/computeMetadata/v1/instance/$Key"
|
||||
try {
|
||||
$client = New-Object Net.WebClient
|
||||
$client.Headers.Add('Metadata-Flavor', 'Google')
|
||||
@ -95,6 +94,18 @@ function Get-InstanceMetadataValue {
|
||||
}
|
||||
}
|
||||
|
||||
# Returns the GCE instance metadata value for $Key where key is an "attribute"
|
||||
# of the instance. If the key is not present in the instance metadata returns
|
||||
# $Default if set, otherwise returns $null.
|
||||
function Get-InstanceMetadataAttribute {
|
||||
param (
|
||||
[parameter(Mandatory=$true)] [string]$Key,
|
||||
[parameter(Mandatory=$false)] [string]$Default
|
||||
)
|
||||
|
||||
return Get-InstanceMetadata "attributes/$Key" $Default
|
||||
}
|
||||
|
||||
function Validate-SHA1 {
|
||||
param(
|
||||
[parameter(Mandatory=$true)] [string]$Hash,
|
||||
|
@ -33,9 +33,10 @@ $ErrorActionPreference = 'Stop'
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
|
||||
# Returns the GCE instance metadata value for $Key. If the key is not present
|
||||
# in the instance metadata returns $Default if set, otherwise returns $null.
|
||||
function Get-InstanceMetadataValue {
|
||||
# Returns the GCE instance metadata value for $Key where key is an "attribute"
|
||||
# of the instance. If the key is not present in the instance metadata returns
|
||||
# $Default if set, otherwise returns $null.
|
||||
function Get-InstanceMetadataAttribute {
|
||||
param (
|
||||
[parameter(Mandatory=$true)] [string]$Key,
|
||||
[parameter(Mandatory=$false)] [string]$Default
|
||||
@ -69,7 +70,7 @@ function FetchAndImport-ModuleFromMetadata {
|
||||
[parameter(Mandatory=$true)] [string]$Filename
|
||||
)
|
||||
|
||||
$module = Get-InstanceMetadataValue $MetadataKey
|
||||
$module = Get-InstanceMetadataAttribute $MetadataKey
|
||||
if (Test-Path C:\$Filename) {
|
||||
if (-not $REDO_STEPS) {
|
||||
Log-Output "Skip: C:\$Filename already exists, not overwriting"
|
||||
@ -87,7 +88,7 @@ try {
|
||||
# Don't use FetchAndImport-ModuleFromMetadata for common.psm1 - the common
|
||||
# module includes variables and functions that any other function may depend
|
||||
# on.
|
||||
$module = Get-InstanceMetadataValue 'common-psm1'
|
||||
$module = Get-InstanceMetadataAttribute 'common-psm1'
|
||||
New-Item -ItemType file -Force C:\common.psm1 | Out-Null
|
||||
Set-Content C:\common.psm1 $module
|
||||
Import-Module -Force C:\common.psm1
|
||||
@ -96,6 +97,7 @@ try {
|
||||
# then put these calls into a loop over a list of XYZ-psm1 keys.
|
||||
FetchAndImport-ModuleFromMetadata 'k8s-node-setup-psm1' 'k8s-node-setup.psm1'
|
||||
|
||||
Dump-DebugInfoToConsole
|
||||
Set-PrerequisiteOptions
|
||||
$kube_env = Fetch-KubeEnv
|
||||
Disable-WindowsDefender
|
||||
|
@ -134,6 +134,19 @@ function Add_GceMetadataServerRoute {
|
||||
}
|
||||
}
|
||||
|
||||
# Writes debugging information, such as Windows version and patch info, to the
|
||||
# console.
|
||||
function Dump-DebugInfoToConsole {
|
||||
Try {
|
||||
$version = "$([System.Environment]::OSVersion.Version | Out-String)"
|
||||
$hotfixes = "$(Get-Hotfix | Out-String)"
|
||||
$image = "$(Get-InstanceMetadata 'image' | Out-String)"
|
||||
Log-Output "Windows version:`n$version"
|
||||
Log-Output "Installed hotfixes:`n$hotfixes"
|
||||
Log-Output "GCE Windows image:`n$image"
|
||||
} Catch { }
|
||||
}
|
||||
|
||||
# Fetches the kube-env from the instance metadata.
|
||||
#
|
||||
# Returns: a PowerShell Hashtable object containing the key-value pairs from
|
||||
@ -141,7 +154,7 @@ function Add_GceMetadataServerRoute {
|
||||
function Fetch-KubeEnv {
|
||||
# Testing / debugging:
|
||||
# First:
|
||||
# ${kube_env} = Get-InstanceMetadataValue 'kube-env'
|
||||
# ${kube_env} = Get-InstanceMetadataAttribute 'kube-env'
|
||||
# or:
|
||||
# ${kube_env} = [IO.File]::ReadAllText(".\kubeEnv.txt")
|
||||
# ${kube_env_table} = ConvertFrom-Yaml ${kube_env}
|
||||
@ -149,7 +162,7 @@ function Fetch-KubeEnv {
|
||||
# ${kube_env_table}.GetType()
|
||||
|
||||
# The type of kube_env is a powershell String.
|
||||
$kube_env = Get-InstanceMetadataValue 'kube-env'
|
||||
$kube_env = Get-InstanceMetadataAttribute 'kube-env'
|
||||
$kube_env_table = ConvertFrom-Yaml ${kube_env}
|
||||
return ${kube_env_table}
|
||||
}
|
||||
@ -888,7 +901,7 @@ function Configure-Kubelet {
|
||||
# The Kubelet config is built by build-kubelet-config() in
|
||||
# cluster/gce/util.sh, and stored in the metadata server under the
|
||||
# 'kubelet-config' key.
|
||||
$kubelet_config = Get-InstanceMetadataValue 'kubelet-config'
|
||||
$kubelet_config = Get-InstanceMetadataAttribute 'kubelet-config'
|
||||
Set-Content ${env:KUBELET_CONFIG} $kubelet_config
|
||||
Log-Output "Kubelet config:`n$(Get-Content -Raw ${env:KUBELET_CONFIG})"
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ function Setup_WriteSshKeysScript {
|
||||
|
||||
# Fetch helper module for manipulating Windows user profiles.
|
||||
if (ShouldWrite-File $USER_PROFILE_MODULE) {
|
||||
$module = Get-InstanceMetadataValue 'user-profile-psm1'
|
||||
$module = Get-InstanceMetadataAttribute 'user-profile-psm1'
|
||||
New-Item -ItemType file -Force $USER_PROFILE_MODULE | Out-Null
|
||||
Set-Content $USER_PROFILE_MODULE $module
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user