Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-v3.27] Auto pick #8563: Run token refresher on Windows #8571

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions node/windows-packaging/CalicoWindows/node/node-service.ps1
Expand Up @@ -18,6 +18,38 @@
ipmo .\libs\calico\calico.psm1 -Force
ipmo .\libs\hns\hns.psm1 -Force -DisableNameChecking

function Get-TokenRefresherPid()
{
return $(Get-WmiObject Win32_Process -Filter "name = 'calico-node.exe'" | Select-Object CommandLine, ProcessId | Where-Object -Property CommandLine -match ".*calico-node.exe.*-monitor-token.*").ProcessId
}

function Start-TokenRefresher()
{
Write-Host "Starting Calico token refresher..."
Start-Process -NoNewWindow .\calico-node.exe -ArgumentList "-monitor-token"
Write-Host "Calico token refresher running on PID" $(Get-TokenRefresherPid)
}

function Ensure-TokenRefresher()
{
if (-not $(Get-TokenRefresherPid))
{
Write-Host "Calico token refresher is not running, restarting it"
Start-TokenRefresher
}
}

function Restart-TokenRefresher()
{
$tokenRefresherPid = Get-TokenRefresherPid
if ($tokenRefresherPid)
{
Write-Host "Restarting Calico token refresher"
Stop-Process -force -Id $tokenRefresherPid
}
Start-TokenRefresher
}

$lastBootTime = Get-LastBootTime
$Stored = Get-StoredLastBootTime
Write-Host "StoredLastBootTime $Stored, CurrentLastBootTime $lastBootTime"
Expand Down Expand Up @@ -165,6 +197,7 @@ while ($True)
if ($LastExitCode -EQ 0)
{
Write-Host "Calico node initialisation succeeded; monitoring kubelet for restarts..."
Restart-TokenRefresher
break
}

Expand All @@ -191,5 +224,7 @@ while ($True)
}
}

Ensure-TokenRefresher

Start-Sleep 10
}