Skip to content

Commit 0a1e589

Browse files
authored
Merge pull request kubernetes#92123 from YangLu1031/improveStackdriverInstallation
Stabilize StackdriverLogging installation
2 parents 73fa63a + 0239a7d commit 0a1e589

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,38 @@ function Restart-LoggingAgent {
15401540
Start-Service StackdriverLogging
15411541
}
15421542

1543+
# Check whether the logging agent is installed by whether it's registered as service
1544+
function IsLoggingAgentInstalled {
1545+
$stackdriver_status = (Get-Service StackdriverLogging -ErrorAction Ignore).Status
1546+
return -not [string]::IsNullOrEmpty($stackdriver_status)
1547+
}
1548+
1549+
# Clean up the logging agent's registry key and root folder if they exist from a prior installation.
1550+
# Try to uninstall it first, if it failed, remove the registry key at least,
1551+
# as the registry key will block the silent installation later on.
1552+
function Cleanup-LoggingAgent {
1553+
# For 64 bits app, the registry path is 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
1554+
# for 32 bits app, it's 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
1555+
# StackdriverLogging is installed as 32 bits app
1556+
$x32_app_reg = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
1557+
$uninstall_string = (Get-ChildItem $x32_app_reg | Get-ItemProperty | Where-Object {$_.DisplayName -match "Stackdriver"}).UninstallString
1558+
if (-not [string]::IsNullOrEmpty($uninstall_string)) {
1559+
try {
1560+
Start-Process -FilePath "$uninstall_string" -ArgumentList "/S" -Wait
1561+
} catch {
1562+
Log-Output "Exception happens during uninstall logging agent, so remove the registry key at least"
1563+
Remove-Item -Path "$x32_app_reg\GoogleStackdriverLoggingAgent\"
1564+
}
1565+
}
1566+
1567+
# If we chose reboot after uninstallation, the root folder would be clean.
1568+
# But since we couldn't reboot, so some files & folders would be left there,
1569+
# which could block the re-installation later on, so clean it up
1570+
if(Test-Path $STACKDRIVER_ROOT){
1571+
Remove-Item -Force -Recurse $STACKDRIVER_ROOT
1572+
}
1573+
}
1574+
15431575
# Installs the Stackdriver logging agent according to
15441576
# https://cloud.google.com/logging/docs/agent/installation.
15451577
# TODO(yujuhong): Update to a newer Stackdriver agent once it is released to
@@ -1556,17 +1588,18 @@ function Install-LoggingAgent {
15561588
("$STACKDRIVER_ROOT\LoggingAgent\Main\pos\winevtlog.pos\worker0\" +
15571589
"storage.json")
15581590

1559-
if (Test-Path $STACKDRIVER_ROOT) {
1591+
if (IsLoggingAgentInstalled) {
15601592
# Note: we should reinstall the Stackdriver agent if $REDO_STEPS is true
15611593
# here, but we don't know how to run the installer without it prompting
15621594
# when Stackdriver is already installed. We dumped the strings in the
15631595
# installer binary and searched for flags to do this but found nothing. Oh
15641596
# well.
1565-
Log-Output ("Skip: $STACKDRIVER_ROOT is already present, assuming that " +
1566-
"Stackdriver logging agent is already installed")
1567-
Restart-LoggingAgent
1597+
Log-Output ("Skip: Stackdriver logging agent is already installed")
15681598
return
15691599
}
1600+
1601+
# After a crash, the StackdriverLogging service could be missing, but its files will still be present
1602+
Cleanup-LoggingAgent
15701603

15711604
$url = ("https://storage.googleapis.com/gke-release/winnode/stackdriver/" +
15721605
"StackdriverLogging-${STACKDRIVER_VERSION}.exe")

0 commit comments

Comments
 (0)