Skip to content

Commit 9614a85

Browse files
authored
Merge pull request kubernetes#81300 from liyanhui1228/sd_logging
Install and start logging agent based on kube env
2 parents 2e6b073 + 1d27242 commit 9614a85

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

cluster/gce/windows/configure.ps1

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@ function FetchAndImport-ModuleFromMetadata {
8484
Import-Module -Force C:\$Filename
8585
}
8686

87+
# Returns true if the ENABLE_STACKDRIVER_WINDOWS or ENABLE_NODE_LOGGING field in kube_env is true.
88+
# $KubeEnv is a hash table containing the kube-env metadata keys+values.
89+
# ENABLE_NODE_LOGGING is used for legacy Stackdriver Logging, and will be deprecated (always set to False)
90+
# soon. ENABLE_STACKDRIVER_WINDOWS is added to indicate whether logging is enabled for windows nodes.
91+
function IsLoggingEnabled {
92+
param (
93+
[parameter(Mandatory=$true)] [hashtable]$KubeEnv
94+
)
95+
96+
if ($KubeEnv.Contains('ENABLE_STACKDRIVER_WINDOWS') -and `
97+
($KubeEnv['ENABLE_STACKDRIVER_WINDOWS'] -eq 'true')) {
98+
return $true
99+
} elseif ($KubeEnv.Contains('ENABLE_NODE_LOGGING') -and `
100+
($KubeEnv['ENABLE_NODE_LOGGING'] -eq 'true')) {
101+
return $true
102+
}
103+
return $false
104+
}
105+
87106
try {
88107
# Don't use FetchAndImport-ModuleFromMetadata for common.psm1 - the common
89108
# module includes variables and functions that any other function may depend
@@ -112,9 +131,12 @@ try {
112131
Create-Directories
113132
Download-HelperScripts
114133

115-
Install-LoggingAgent
116-
Configure-LoggingAgent
117-
Restart-LoggingAgent
134+
# Even if Stackdriver is already installed, the function will still [re]start the service.
135+
if (IsLoggingEnabled $kube_env) {
136+
Install-LoggingAgent
137+
Configure-LoggingAgent
138+
Restart-LoggingAgent
139+
}
118140

119141
Create-DockerRegistryKey
120142
Configure-Dockerd

0 commit comments

Comments
 (0)