Skip to content

Commit 59e7a4f

Browse files
authored
Merge pull request kubernetes#84434 from yliaog/windows
removed powershell-yaml module dependency
2 parents 28887de + 18f48e2 commit 59e7a4f

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,43 @@ function Dump-DebugInfoToConsole {
147147
} Catch { }
148148
}
149149

150+
# Converts the kube-env string in Yaml
151+
#
152+
# Returns: a PowerShell Hashtable object containing the key-value pairs from
153+
# kube-env.
154+
function ConvertFrom-Yaml-KubeEnv {
155+
param (
156+
[parameter(Mandatory=$true)] [string]$kube_env_str
157+
)
158+
$kube_env_table = @{}
159+
$currentLine = $null
160+
switch -regex (${kube_env_str} -split '\r?\n') {
161+
'^(\S.*)' {
162+
# record start pattern, line that doesn't start with a whitespace
163+
if ($null -ne $currentLine) {
164+
$key, $val = $currentLine -split ":",2
165+
$kube_env_table[$key] = $val.Trim("'", " ", "`"")
166+
}
167+
$currentLine = $matches.1
168+
continue
169+
}
170+
171+
'^(\s+.*)' {
172+
# line that start with whitespace
173+
$currentLine += $matches.1
174+
continue
175+
}
176+
}
177+
178+
# Handle the last line if any
179+
if ($currentLine) {
180+
$key, $val = $currentLine -split ":",2
181+
$kube_env_table[$key] = $val.Trim("'", " ", "`"")
182+
}
183+
184+
return ${kube_env_table}
185+
}
186+
150187
# Fetches the kube-env from the instance metadata.
151188
#
152189
# Returns: a PowerShell Hashtable object containing the key-value pairs from
@@ -157,13 +194,13 @@ function Fetch-KubeEnv {
157194
# ${kube_env} = Get-InstanceMetadataAttribute 'kube-env'
158195
# or:
159196
# ${kube_env} = [IO.File]::ReadAllText(".\kubeEnv.txt")
160-
# ${kube_env_table} = ConvertFrom-Yaml ${kube_env}
197+
# ${kube_env_table} = ConvertFrom-Yaml-KubeEnv ${kube_env}
161198
# ${kube_env_table}
162199
# ${kube_env_table}.GetType()
163200

164201
# The type of kube_env is a powershell String.
165202
$kube_env = Get-InstanceMetadataAttribute 'kube-env'
166-
$kube_env_table = ConvertFrom-Yaml ${kube_env}
203+
$kube_env_table = ConvertFrom-Yaml-KubeEnv ${kube_env}
167204
return ${kube_env_table}
168205
}
169206

@@ -238,10 +275,6 @@ function Set-PrerequisiteOptions {
238275
# Use TLS 1.2: needed for Invoke-WebRequest downloads from github.com.
239276
[Net.ServicePointManager]::SecurityProtocol = `
240277
[Net.SecurityProtocolType]::Tls12
241-
242-
# https://github.com/cloudbase/powershell-yaml
243-
Log-Output "Installing powershell-yaml module from external repo"
244-
Install-Module -Name powershell-yaml -Force
245278
}
246279

247280
# Creates directories where other functions in this module will read and write

0 commit comments

Comments
 (0)