Skip to content
Open
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
67 changes: 67 additions & 0 deletions Kubernetes/windows/debug/MonitorServiceConfiguration.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#Requires -RunAsAdministrator

Param(
[parameter(Mandatory = $false)] [string] $NetworkName = "azure",
[parameter(Mandatory = $false)] [string] $ServiceIP = "20.124.54.159",
[parameter(Mandatory = $false)] [string] $ServicePort = "5555"
)


class LoadBalancerPolicyData {
[string] $Id
[bool] $IsDsr
[bool] $IsVfpHairpinRulePlumbed
}

$networkId = (Get-HnsNetwork -Detailed | Where-Object Name -eq $networkName).Id
$network = Get-HnsNetwork -Id $networkId -Detailed

$hostVfpPort = ($network | ForEach-Object { $_.Layer.Resources.Allocators } | Where-Object Tag -eq "Host Vnic").EndpointPortGuid


[LoadBalancerPolicyData] $loadBalancerPolicy = [LoadBalancerPolicyData]::new()
$loadBalancerPolicy.IsVfpHairpinRulePlumbed = $false

while ($true) {
$loadBalancerPolicyFound= $false
$hnsPolicyList = Get-HnsPolicyList
foreach ($policy in $hnsPolicyList) {
$vip = ""
if ($policy.Policies.LocalRoutedVip) {
$vip = $network.ManagementIP
}
else {
$vip = $policy.Policies.VIPs
}

if (($vip -eq $ServiceIP) -and ($ServicePort -eq $policy.Policies.ExternalPort)) {
$loadBalancerPolicy.Id = $policy.ID
$loadBalancerPolicy.IsDsr = $policy.Policies.IsDSR
$loadBalancerPolicyFound= $true
}
}

if ($loadBalancerPolicyFound -eq $false)
{
$message = "{0} {1} {2} {3}:{4}" -f $(hostname), (Get-Date).ToString(), "HNS Load balancer policy missing for the service", $ServiceIP, $ServicePort
Write-Host $message
}

$hairPinRulePattern = $ServiceIP + "_" + $ServicePort
$hairpinRuleCount = (vfpctrl.exe /port $hostVfpPort /layer SLB_HAIRPIN_LAYER /list-rule | Select-String -Pattern $hairPinRulePattern).Count
$loadBalancerPolicy.IsVfpHairpinRulePlumbed = ($hairpinRuleCount -gt 0)

if ($loadBalancerPolicy.IsVfpHairpinRulePlumbed -eq $false) {
$message = "{0} {1} {2} {3}:{4}" -f $(hostname), (Get-Date).ToString(), "Hairpin rule missing for the Service", $ServiceIP, $ServicePort
Write-Host $message
}

Start-Sleep -Milliseconds 500
}