Skip to content

Commit 0239a7d

Browse files
committed
Stabilize stackdriver installation
1 parent e621438 commit 0239a7d

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
@@ -1532,6 +1532,38 @@ function Restart-LoggingAgent {
15321532
Start-Service StackdriverLogging
15331533
}
15341534

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

1551-
if (Test-Path $STACKDRIVER_ROOT) {
1583+
if (IsLoggingAgentInstalled) {
15521584
# Note: we should reinstall the Stackdriver agent if $REDO_STEPS is true
15531585
# here, but we don't know how to run the installer without it prompting
15541586
# when Stackdriver is already installed. We dumped the strings in the
15551587
# installer binary and searched for flags to do this but found nothing. Oh
15561588
# well.
1557-
Log-Output ("Skip: $STACKDRIVER_ROOT is already present, assuming that " +
1558-
"Stackdriver logging agent is already installed")
1559-
Restart-LoggingAgent
1589+
Log-Output ("Skip: Stackdriver logging agent is already installed")
15601590
return
15611591
}
1592+
1593+
# After a crash, the StackdriverLogging service could be missing, but its files will still be present
1594+
Cleanup-LoggingAgent
15621595

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

0 commit comments

Comments
 (0)