From 53a2559e244c3324026b1ea3470af1791f525287 Mon Sep 17 00:00:00 2001 From: Angela Li Date: Mon, 12 Aug 2019 11:07:50 -0700 Subject: [PATCH 1/4] Install and start logging based on kube env --- cluster/gce/windows/configure.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cluster/gce/windows/configure.ps1 b/cluster/gce/windows/configure.ps1 index 800e9e5f3be..7f16448bf00 100644 --- a/cluster/gce/windows/configure.ps1 +++ b/cluster/gce/windows/configure.ps1 @@ -84,6 +84,20 @@ function FetchAndImport-ModuleFromMetadata { Import-Module -Force C:\$Filename } +# Returns true if the ENABLE_NODE_LOGGING field in kube_env is true. +# $KubeEnv is a hash table containing the kube-env metadata keys+values. +function IsLoggingEnabled { + param ( + [parameter(Mandatory=$true)] [hashtable]$KubeEnv + ) + + if ($KubeEnv.Contains('ENABLE_NODE_LOGGING') -and ` + ($KubeEnv['ENABLE_NODE_LOGGING'] -eq 'true')) { + return $true + } + return $false +} + try { # Don't use FetchAndImport-ModuleFromMetadata for common.psm1 - the common # module includes variables and functions that any other function may depend @@ -108,6 +122,10 @@ try { StartProcess-WriteSshKeys } + if (IsLoggingEnabled $kube_env) { + InstallAndStart-LoggingAgent + } + Set-EnvironmentVars Create-Directories Download-HelperScripts From f24749594b3a1ea7f014775fd0b3ed8e8d96d653 Mon Sep 17 00:00:00 2001 From: Angela Li Date: Tue, 3 Sep 2019 12:52:24 -0700 Subject: [PATCH 2/4] Adding ENABLE_STACKDRIVER_WINDOWS --- cluster/gce/windows/configure.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cluster/gce/windows/configure.ps1 b/cluster/gce/windows/configure.ps1 index 7f16448bf00..aedf681441a 100644 --- a/cluster/gce/windows/configure.ps1 +++ b/cluster/gce/windows/configure.ps1 @@ -84,14 +84,19 @@ function FetchAndImport-ModuleFromMetadata { Import-Module -Force C:\$Filename } -# Returns true if the ENABLE_NODE_LOGGING field in kube_env is true. +# Returns true if the ENABLE_STACKDRIVER_WINDOWS or ENABLE_NODE_LOGGING field in kube_env is true. # $KubeEnv is a hash table containing the kube-env metadata keys+values. +# ENABLE_NODE_LOGGING is used for legacy Stackdriver Logging, and will be deprecated (always set to False) +# soon. ENABLE_STACKDRIVER_WINDOWS is added to indicate whether logging is enabled for windows nodes. function IsLoggingEnabled { param ( [parameter(Mandatory=$true)] [hashtable]$KubeEnv ) - if ($KubeEnv.Contains('ENABLE_NODE_LOGGING') -and ` + if ($KubeEnv.Contains('ENABLE_STACKDRIVER_WINDOWS') -and ` + ($KubeEnv['ENABLE_STACKDRIVER_WINDOWS'] -eq 'true')) { + return $true + } elseif ($KubeEnv.Contains('ENABLE_NODE_LOGGING') -and ` ($KubeEnv['ENABLE_NODE_LOGGING'] -eq 'true')) { return $true } From 54d9f9a75b4e46abf6672d930f27cc5c7b9784da Mon Sep 17 00:00:00 2001 From: Angela Li Date: Tue, 3 Sep 2019 13:03:01 -0700 Subject: [PATCH 3/4] Add comment --- cluster/gce/windows/configure.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/cluster/gce/windows/configure.ps1 b/cluster/gce/windows/configure.ps1 index aedf681441a..99cf5e2496d 100644 --- a/cluster/gce/windows/configure.ps1 +++ b/cluster/gce/windows/configure.ps1 @@ -127,6 +127,7 @@ try { StartProcess-WriteSshKeys } + # Even if Stackdriver is already installed, the function will still [re]start the service. if (IsLoggingEnabled $kube_env) { InstallAndStart-LoggingAgent } From 1d2724296727fb4a456d74f7d1a54787030d8416 Mon Sep 17 00:00:00 2001 From: Angela Li Date: Wed, 4 Sep 2019 15:32:25 -0700 Subject: [PATCH 4/4] rebase --- cluster/gce/windows/configure.ps1 | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cluster/gce/windows/configure.ps1 b/cluster/gce/windows/configure.ps1 index 99cf5e2496d..400d659e157 100644 --- a/cluster/gce/windows/configure.ps1 +++ b/cluster/gce/windows/configure.ps1 @@ -127,18 +127,16 @@ try { StartProcess-WriteSshKeys } - # Even if Stackdriver is already installed, the function will still [re]start the service. - if (IsLoggingEnabled $kube_env) { - InstallAndStart-LoggingAgent - } - Set-EnvironmentVars Create-Directories Download-HelperScripts - Install-LoggingAgent - Configure-LoggingAgent - Restart-LoggingAgent + # Even if Stackdriver is already installed, the function will still [re]start the service. + if (IsLoggingEnabled $kube_env) { + Install-LoggingAgent + Configure-LoggingAgent + Restart-LoggingAgent + } Create-DockerRegistryKey Configure-Dockerd