Skip to content

Commit 98c0d15

Browse files
authored
Merge pull request kubernetes#74762 from pjh/gce-windows-dump-versions
Dump Windows version information during cluster bringup.
2 parents 983cf51 + 18a2a98 commit 98c0d15

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

cluster/gce/windows/common.psm1

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ function ShouldWrite-File {
7171

7272
# Returns the GCE instance metadata value for $Key. If the key is not present
7373
# in the instance metadata returns $Default if set, otherwise returns $null.
74-
function Get-InstanceMetadataValue {
74+
function Get-InstanceMetadata {
7575
param (
7676
[parameter(Mandatory=$true)] [string]$Key,
7777
[parameter(Mandatory=$false)] [string]$Default
7878
)
7979

80-
$url = ("http://metadata.google.internal/computeMetadata/v1/instance/" +
81-
"attributes/$Key")
80+
$url = "http://metadata.google.internal/computeMetadata/v1/instance/$Key"
8281
try {
8382
$client = New-Object Net.WebClient
8483
$client.Headers.Add('Metadata-Flavor', 'Google')
@@ -95,6 +94,18 @@ function Get-InstanceMetadataValue {
9594
}
9695
}
9796

97+
# Returns the GCE instance metadata value for $Key where key is an "attribute"
98+
# of the instance. If the key is not present in the instance metadata returns
99+
# $Default if set, otherwise returns $null.
100+
function Get-InstanceMetadataAttribute {
101+
param (
102+
[parameter(Mandatory=$true)] [string]$Key,
103+
[parameter(Mandatory=$false)] [string]$Default
104+
)
105+
106+
return Get-InstanceMetadata "attributes/$Key" $Default
107+
}
108+
98109
function Validate-SHA1 {
99110
param(
100111
[parameter(Mandatory=$true)] [string]$Hash,

cluster/gce/windows/configure.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ $ErrorActionPreference = 'Stop'
3333
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
3434
$ProgressPreference = 'SilentlyContinue'
3535

36-
# Returns the GCE instance metadata value for $Key. If the key is not present
37-
# in the instance metadata returns $Default if set, otherwise returns $null.
38-
function Get-InstanceMetadataValue {
36+
# Returns the GCE instance metadata value for $Key where key is an "attribute"
37+
# of the instance. If the key is not present in the instance metadata returns
38+
# $Default if set, otherwise returns $null.
39+
function Get-InstanceMetadataAttribute {
3940
param (
4041
[parameter(Mandatory=$true)] [string]$Key,
4142
[parameter(Mandatory=$false)] [string]$Default
@@ -69,7 +70,7 @@ function FetchAndImport-ModuleFromMetadata {
6970
[parameter(Mandatory=$true)] [string]$Filename
7071
)
7172

72-
$module = Get-InstanceMetadataValue $MetadataKey
73+
$module = Get-InstanceMetadataAttribute $MetadataKey
7374
if (Test-Path C:\$Filename) {
7475
if (-not $REDO_STEPS) {
7576
Log-Output "Skip: C:\$Filename already exists, not overwriting"
@@ -87,7 +88,7 @@ try {
8788
# Don't use FetchAndImport-ModuleFromMetadata for common.psm1 - the common
8889
# module includes variables and functions that any other function may depend
8990
# on.
90-
$module = Get-InstanceMetadataValue 'common-psm1'
91+
$module = Get-InstanceMetadataAttribute 'common-psm1'
9192
New-Item -ItemType file -Force C:\common.psm1 | Out-Null
9293
Set-Content C:\common.psm1 $module
9394
Import-Module -Force C:\common.psm1
@@ -96,6 +97,7 @@ try {
9697
# then put these calls into a loop over a list of XYZ-psm1 keys.
9798
FetchAndImport-ModuleFromMetadata 'k8s-node-setup-psm1' 'k8s-node-setup.psm1'
9899

100+
Dump-DebugInfoToConsole
99101
Set-PrerequisiteOptions
100102
$kube_env = Fetch-KubeEnv
101103
Disable-WindowsDefender

cluster/gce/windows/k8s-node-setup.psm1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,35 @@ function Add_GceMetadataServerRoute {
134134
}
135135
}
136136

137+
# Writes debugging information, such as Windows version and patch info, to the
138+
# console.
139+
function Dump-DebugInfoToConsole {
140+
Try {
141+
$version = "$([System.Environment]::OSVersion.Version | Out-String)"
142+
$hotfixes = "$(Get-Hotfix | Out-String)"
143+
$image = "$(Get-InstanceMetadata 'image' | Out-String)"
144+
Log-Output "Windows version:`n$version"
145+
Log-Output "Installed hotfixes:`n$hotfixes"
146+
Log-Output "GCE Windows image:`n$image"
147+
} Catch { }
148+
}
149+
137150
# Fetches the kube-env from the instance metadata.
138151
#
139152
# Returns: a PowerShell Hashtable object containing the key-value pairs from
140153
# kube-env.
141154
function Fetch-KubeEnv {
142155
# Testing / debugging:
143156
# First:
144-
# ${kube_env} = Get-InstanceMetadataValue 'kube-env'
157+
# ${kube_env} = Get-InstanceMetadataAttribute 'kube-env'
145158
# or:
146159
# ${kube_env} = [IO.File]::ReadAllText(".\kubeEnv.txt")
147160
# ${kube_env_table} = ConvertFrom-Yaml ${kube_env}
148161
# ${kube_env_table}
149162
# ${kube_env_table}.GetType()
150163

151164
# The type of kube_env is a powershell String.
152-
$kube_env = Get-InstanceMetadataValue 'kube-env'
165+
$kube_env = Get-InstanceMetadataAttribute 'kube-env'
153166
$kube_env_table = ConvertFrom-Yaml ${kube_env}
154167
return ${kube_env_table}
155168
}
@@ -888,7 +901,7 @@ function Configure-Kubelet {
888901
# The Kubelet config is built by build-kubelet-config() in
889902
# cluster/gce/util.sh, and stored in the metadata server under the
890903
# 'kubelet-config' key.
891-
$kubelet_config = Get-InstanceMetadataValue 'kubelet-config'
904+
$kubelet_config = Get-InstanceMetadataAttribute 'kubelet-config'
892905
Set-Content ${env:KUBELET_CONFIG} $kubelet_config
893906
Log-Output "Kubelet config:`n$(Get-Content -Raw ${env:KUBELET_CONFIG})"
894907
}

cluster/gce/windows/testonly/install-ssh.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function Setup_WriteSshKeysScript {
112112

113113
# Fetch helper module for manipulating Windows user profiles.
114114
if (ShouldWrite-File $USER_PROFILE_MODULE) {
115-
$module = Get-InstanceMetadataValue 'user-profile-psm1'
115+
$module = Get-InstanceMetadataAttribute 'user-profile-psm1'
116116
New-Item -ItemType file -Force $USER_PROFILE_MODULE | Out-Null
117117
Set-Content $USER_PROFILE_MODULE $module
118118
}

0 commit comments

Comments
 (0)