Skip to content

Commit

Permalink
Run token refresher on Windows
Browse files Browse the repository at this point in the history
Add running of token refresher (calico-node -monitor-token)
to the 'node' container on Calico for Windows.
  • Loading branch information
coutinhop committed Feb 28, 2024
1 parent 36413f2 commit ad7c03a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions node/windows-packaging/CalicoWindows/node/node-service.ps1
Original file line number Diff line number Diff line change
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 ad7c03a

Please sign in to comment.