Skip to content

Commit

Permalink
Merge pull request #8571 from coutinhop/auto-pick-of-#8563-upstream-r…
Browse files Browse the repository at this point in the history
…elease-v3.27

[release-v3.27] Auto pick #8563: Run token refresher on Windows
  • Loading branch information
coutinhop committed Feb 28, 2024
2 parents 36413f2 + ad7c03a commit f26f2e1
Showing 1 changed file with 35 additions and 0 deletions.
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
}

0 comments on commit f26f2e1

Please sign in to comment.