Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions kubernetes/windows/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@
}
}

function Test-TcpListenerByConnect {
param (
[int]$port,
[int]$timeoutMs = 2000
)

# Probe the listener by actually connecting to it rather than enumerating sockets.
# On Windows Server 2025 hosts, netstat and Get-NetTCPConnection return no rows inside the
# container even though the listener is present and accepting connections, which made the
# previous netstat-based check fail forever and prevented telegraf from ever starting.
$client = New-Object System.Net.Sockets.TcpClient
try {
$asyncResult = $client.BeginConnect('127.0.0.1', $port, $null, $null)
if (-not $asyncResult.AsyncWaitHandle.WaitOne($timeoutMs)) {
return $false
}
$client.EndConnect($asyncResult)
return $client.Connected
}
catch {
return $false
}
finally {
$client.Close()
}
}

function Test-FluentbitTcpListener {
param (
[int]$port
Expand All @@ -54,17 +81,19 @@
$retryCount = [int]$waitTimeSecs
$retryAttempts = 0
$retryDelaySeconds = 1
while ($retryAttempts -lt $retryCount) {
# Bound the loop by wall-clock time so the configured wait window is honored regardless of
# how long an individual connect probe takes to fail.
$deadline = (Get-Date).AddSeconds($retryCount)
while ((Get-Date) -lt $deadline) {
$retryAttempts++
Write-Host "Test-FluentbitTcpListener: Retry attempt $retryAttempts/$retryCount..."
$netstatOutput = netstat -an | Select-String "LISTENING"
if ($netstatOutput -match ":$port") {
Write-Host "Test-FluentbitTcpListener: Retry attempt $retryAttempts (waiting up to $retryCount seconds)..."
if (Test-TcpListenerByConnect -port $port -timeoutMs 1000) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work for both ws2022 and ws2025?

Write-Host "Test-FluentbitTcpListener: Fluentbit TCP listener is UP and running on port $port."
return $true
}
Start-Sleep -Seconds $retryDelaySeconds
}
Write-Host "Test-FluentbitTcpListener: Failed to detect TCP listener after $retryCount attempts. Exiting script."
Write-Host "Test-FluentbitTcpListener: Failed to detect TCP listener within $retryCount seconds ($retryAttempts attempts). Exiting script."
return $false
}

Expand Down
1 change: 0 additions & 1 deletion test/scenario/log-gen-all-nodes-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ spec:
spec:
nodeSelector:
kubernetes.io/os: windows
kubernetes.azure.com/os-sku: Windows2022
tolerations:
- operator: Exists
containers:
Expand Down
Loading