@@ -147,6 +147,43 @@ function Dump-DebugInfoToConsole {
147
147
} Catch { }
148
148
}
149
149
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
+
150
187
# Fetches the kube-env from the instance metadata.
151
188
#
152
189
# Returns: a PowerShell Hashtable object containing the key-value pairs from
@@ -157,13 +194,13 @@ function Fetch-KubeEnv {
157
194
# ${kube_env} = Get-InstanceMetadataAttribute 'kube-env'
158
195
# or:
159
196
# ${kube_env} = [IO.File]::ReadAllText(".\kubeEnv.txt")
160
- # ${kube_env_table} = ConvertFrom-Yaml ${kube_env}
197
+ # ${kube_env_table} = ConvertFrom-Yaml-KubeEnv ${kube_env}
161
198
# ${kube_env_table}
162
199
# ${kube_env_table}.GetType()
163
200
164
201
# The type of kube_env is a powershell String.
165
202
$kube_env = Get-InstanceMetadataAttribute ' kube-env'
166
- $kube_env_table = ConvertFrom-Yaml ${kube_env}
203
+ $kube_env_table = ConvertFrom-Yaml - KubeEnv ${kube_env}
167
204
return ${kube_env_table}
168
205
}
169
206
@@ -238,10 +275,6 @@ function Set-PrerequisiteOptions {
238
275
# Use TLS 1.2: needed for Invoke-WebRequest downloads from github.com.
239
276
[Net.ServicePointManager ]::SecurityProtocol = `
240
277
[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
245
278
}
246
279
247
280
# Creates directories where other functions in this module will read and write
0 commit comments