Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
43556be5
Commit
43556be5
authored
Feb 28, 2019
by
Peter Hornyack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance metadata fetching functions.
Introduce Get-InstanceMetadata which can be used to fetch non-"attribute" metadata values.
parent
e476ab63
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
12 deletions
+24
-12
common.psm1
cluster/gce/windows/common.psm1
+14
-3
configure.ps1
cluster/gce/windows/configure.ps1
+6
-5
k8s-node-setup.psm1
cluster/gce/windows/k8s-node-setup.psm1
+3
-3
install-ssh.psm1
cluster/gce/windows/testonly/install-ssh.psm1
+1
-1
No files found.
cluster/gce/windows/common.psm1
View file @
43556be5
...
...
@@ -65,14 +65,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-InstanceMetadata
Value
{
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'
)
...
...
@@ -89,6 +88,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
,
...
...
cluster/gce/windows/configure.ps1
View file @
43556be5
...
...
@@ -27,9 +27,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
...
...
@@ -63,7 +64,7 @@ function FetchAndImport-ModuleFromMetadata {
[
parameter
(
Mandatory
=
$true
)]
[
string
]
$Filename
)
$module
=
Get-InstanceMetadata
Valu
e
$MetadataKey
$module
=
Get-InstanceMetadata
Attribut
e
$MetadataKey
if
(
Test-Path
C:\
$Filename
)
{
if
(
-not
$REDO_STEPS
)
{
Log-Output
"Skip: C:\
$Filename
already exists, not overwriting"
...
...
@@ -81,7 +82,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-InstanceMetadata
Valu
e
'common-psm1'
$module
=
Get-InstanceMetadata
Attribut
e
'common-psm1'
New-Item
-ItemType file -Force C:\common.psm1 | Out-Null
Set-Content
C:\common.psm1
$module
Import-Module -Force C:\common.psm1
...
...
cluster/gce/windows/k8s-node-setup.psm1
View file @
43556be5
...
...
@@ -135,7 +135,7 @@ function Add_GceMetadataServerRoute {
function
Fetch-KubeEnv
{
# Testing / debugging:
# First:
# ${kube_env} = Get-InstanceMetadata
Valu
e 'kube-env'
# ${kube_env} = Get-InstanceMetadata
Attribut
e 'kube-env'
# or:
# ${kube_env} = [IO.File]::ReadAllText(".\kubeEnv.txt")
# ${kube_env_table} = ConvertFrom-Yaml ${kube_env}
...
...
@@ -143,7 +143,7 @@ function Fetch-KubeEnv {
# ${kube_env_table}.GetType()
# The type of kube_env is a powershell String.
$kube_env
=
Get-InstanceMetadata
Valu
e
'kube-env'
$kube_env
=
Get-InstanceMetadata
Attribut
e
'kube-env'
$kube_env_table
=
ConvertFrom-Yaml
${
kube_env
}
return
${
kube_env_table
}
}
...
...
@@ -882,7 +882,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-InstanceMetadata
Valu
e
'kubelet-config'
$kubelet_config
=
Get-InstanceMetadata
Attribut
e
'kubelet-config'
Set-Content
${
env
:KUBELET_CONFIG
}
$kubelet_config
Log-Output
"Kubelet config:
`n
$(
Get-Content
-Raw
${
env
:KUBELET_CONFIG
})
"
}
...
...
cluster/gce/windows/testonly/install-ssh.psm1
View file @
43556be5
...
...
@@ -106,7 +106,7 @@ function Setup_WriteSshKeysScript {
# Fetch helper module for manipulating Windows user profiles.
if
(
ShouldWrite-File
$USER_PROFILE_MODULE
)
{
$module
=
Get-InstanceMetadata
Valu
e
'user-profile-psm1'
$module
=
Get-InstanceMetadata
Attribut
e
'user-profile-psm1'
New-Item
-ItemType file -Force
$USER_PROFILE_MODULE
| Out-Null
Set-Content
$USER_PROFILE_MODULE
$module
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment