Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
45 changes: 45 additions & 0 deletions scripts/duplicateIpDetection/DetectDuplicateIpAddr.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Write-Host "Detecting duplicate IP addresses on the node..."

$BaseDir = "c:\k\debug"

Write-Host "Trying to load HNS module..."

ipmo $BaseDir\hns.v2.psm1 -Force | Write-Host

while($true){
$ipAddresses = ((Get-HnsEndpoint).IpConfigurations).IpAddress

Write-Host "IP addresses on the node:"
foreach($ip in $ipAddresses){
Write-Host $ip
}

Write-Host "Checking for duplicate IP addresses inside the loop..."
$duplicateIpAddr = $ipAddresses | Group-Object | Where-Object { $_.Count -gt 1 }

if($duplicateIpAddr.Count -gt 0){
break
}

Start-Sleep -Seconds 300
}

Write-Host "Duplicate IP addresses found on the node, Duplicate IP addresses are:"

foreach($ipGroup in $duplicateIpAddr){
foreach($ip in $ipGroup.Group){
Write-Host $ip
}
}

Write-Host "Collecting Windows logs..."
$collectWindowsLogs = "$BaseDir\collect-windows-logs.ps1"
powershell $collectWindowsLogs | Write-Host

Write-Host "Collected Windows logs are at $PWD"

Write-Host "Issue has been detected, going into infinite loop to keep the container running..."
while($true){
Write-Host "Container is running in infinte while..."
Start-Sleep -Seconds 3600
}
31 changes: 31 additions & 0 deletions scripts/duplicateIpDetection/DetectDuplicateIpAddress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: DaemonSet
Comment thread
rishu1102 marked this conversation as resolved.
metadata:
name: detect-dup-ip
labels:
app: detect-dup-ip
spec:
selector:
matchLabels:
name: detect-dup-ip
template:
metadata:
labels:
name: detect-dup-ip
spec:
securityContext:
windowsOptions:
hostProcess: true
runAsUserName: "NT AUTHORITY\\SYSTEM"
hostNetwork: true
Comment thread
rishu1102 marked this conversation as resolved.
containers:
- name: detect-dup-ip
image: mcr.microsoft.com/dotnet/framework/samples:aspnetapp
command:
- powershell.exe
- -command
- '$BaseDir = "c:\k\debug"; Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/wcnscripts/refs/heads/user/rishusingh/duplicateIPdetection/scripts/duplicateIpDetection/DetectDuplicateIpAddr.ps1" -OutFile $BaseDir\DetectDuplicateIpAddr.ps1 | Write-Host; cd $BaseDir; .\DetectDuplicateIpAddr.ps1'
securityContext:
privileged: true
nodeSelector:
kubernetes.azure.com/os-sku: Windows2022
7 changes: 7 additions & 0 deletions scripts/duplicateIpDetection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The script uses the Get-HnsEndpoint cmdlet to retrieve all IP addresses associated with the endpoints on the host. It then groups the IP addresses by value and filters the groups to include only those with more than one IP address.

To run the script, open a PowerShell window and run the following command:
PS> .\DetectDuplicateIpAddrs.ps1

Once a duplicate IP address is detected, it breaks out of the while loop and then collects Windows logs on the node.