Skip to content

Commit b3d949a

Browse files
committed
Scripts to identify if the compartmentid in endpoint infor and corresponding namespace info is different.
1 parent de2211a commit b3d949a

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The script extracts the namespaceId and compartmentId from the endpoint information. It then validates the compartmentId against the namespace details. If any anomalies are detected, HNS and TCP/IP traces are captured, along with Windows log collection.
2+
3+
To run the script, open a PowerShell window and run the following command:
4+
PS> .\invalidCompartment.ps1
5+
6+
Or, we can run the scripts under hostprocess daemonset containers using invalidCompartment.yaml
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
function Is-CompartmentIdValid() {
2+
Write-Host "#===== Validating Compartment ID in Endpoint and Namespace =====#"
3+
Write-Host ""
4+
$eps = Get-HnsEndpoint
5+
$nss = Get-HnsNamespace
6+
7+
foreach($ep in $eps) {
8+
if ($ep.Resources.Allocators.CompartmendId.Length -gt 0) {
9+
$compId = [int]$($ep.Resources.Allocators.CompartmendId[0])
10+
$nsId = $ep.Namespace.ID
11+
foreach($ns in $nss) {
12+
if ($ns.ID -Eq $nsId) {
13+
Write-Host "IP Address : $($ep.IPAddress), NamespaceID: $nsId, EPCompID : $compId, NSCompID: $($ns.CompartmentId)"
14+
if ($ns.CompartmentId -NE $compId) {
15+
Write-Host "CompartmentId not matching..."
16+
return $false
17+
} else {
18+
Write-Host "CompartmentId matching..."
19+
}
20+
}
21+
}
22+
}
23+
}
24+
Write-Host ""
25+
return $true
26+
}
27+
28+
$iter = 1
29+
$curLoc = (Get-Location).Path
30+
pktmon stop # Stopping if pktmon is already running
31+
32+
# Start pktmon
33+
Write-Host "#===== Starting pktmon with trace level 6 for TCPIP and Host-Network-Service =====#"
34+
pktmon start --trace -p Microsoft-Windows-TCPIP -k 0xFF -l 6 -p Microsoft-Windows-Host-Network-Service -l 6 -f traces.etl -s 2048
35+
36+
37+
While(Is-CompartmentIdValid) {
38+
$d = Get-Date
39+
Write-Host "#===== Iteration: $iter completed at $d. No issue found. Waiting for 1 minute for next iteration. =====#"
40+
Write-Host ""
41+
Start-Sleep -Seconds 60
42+
$iter++
43+
}
44+
45+
Write-Host "#===== Issue detected. Waiting for 1 minute before Stopping pktmon and collecting logs. =====#"
46+
Start-Sleep -Seconds 60
47+
Write-Host ""
48+
# Stop pktmon
49+
pktmon stop
50+
51+
# Collecting Windows logs
52+
C:\k\debug\collect-windows-logs.ps1
53+
54+
Write-Host "Traces available in $curLoc\traces.etl"
55+
56+
# The below While loop will keep the script running indefinitely keeping the hpc pod alive.
57+
# Without this, the pod will exit after the script execution and restart the process again deleting the logs.
58+
While($true) {
59+
if ($iter -Eq 1) {
60+
Write-Host "The issue was detected on a previously corrupted node, and log rotation may have occurred."
61+
} else {
62+
Write-Host "Issue detected. Please download and review the collected Windows logs and also traces from the following path: $curLoc\traces.etl"
63+
}
64+
Start-Sleep -Seconds 3600
65+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: invalidcompartment
5+
labels:
6+
app: invalidcompartment
7+
spec:
8+
selector:
9+
matchLabels:
10+
name: invalidcompartment
11+
template:
12+
metadata:
13+
labels:
14+
name: invalidcompartment
15+
spec:
16+
securityContext:
17+
windowsOptions:
18+
hostProcess: true
19+
runAsUserName: "NT AUTHORITY\\SYSTEM"
20+
hostNetwork: true
21+
containers:
22+
- name: invalidcompartment
23+
image: mcr.microsoft.com/dotnet/framework/samples:aspnetapp
24+
command:
25+
- powershell.exe
26+
- -command
27+
- |
28+
function Is-CompartmentIdValid { Write-Host "#===== Validating Compartment ID in Endpoint and Namespace =====#"; Write-Host ""; $eps = Get-HnsEndpoint; $nss = Get-HnsNamespace; foreach ($ep in $eps) { if ($ep.Resources.Allocators.CompartmendId.Length -gt 0) { $compId = [int]$($ep.Resources.Allocators.CompartmendId[0]); $nsId = $ep.Namespace.ID; foreach ($ns in $nss) { if ($ns.ID -Eq $nsId) { Write-Host "IP Address : $($ep.IPAddress), NamespaceID: $nsId, EPCompID : $compId, NSCompID: $($ns.CompartmentId)"; if ($ns.CompartmentId -NE $compId) { Write-Host "CompartmentId not matching..."; return $false } else { Write-Host "CompartmentId matching..." } } } } } return $true; }; $iter = 1; $curLoc = (Get-Location).Path; pktmon stop; Write-Host "#===== Starting pktmon with trace level 6 for TCPIP and Host-Network-Service =====#"; pktmon start --trace -p Microsoft-Windows-TCPIP -k 0xFF -l 6 -p Microsoft-Windows-Host-Network-Service -l 6 -f traces.etl -s 2048; while (Is-CompartmentIdValid) { $d = Get-Date; Write-Host "#===== Iteration: $iter completed at $d. No issue found. Waiting for 1 minute for next iteration. =====#"; Write-Host ""; Start-Sleep -Seconds 60; $iter++ }; Write-Host "#===== Issue detected. Waiting for 1 minute before stopping pktmon and collecting logs. =====#"; Start-Sleep -Seconds 60; Write-Host ""; pktmon stop; C:\k\debug\collect-windows-logs.ps1; Write-Host "Traces available in $curLoc\traces.etl"; while ($true) { if ($iter -Eq 1) { Write-Host "The issue was detected on a previously corrupted node, and log rotation may have occurred." } else { Write-Host "Issue detected. Please download and review the collected Windows logs and also traces from the following path: $curLoc\traces.etl" }; Start-Sleep -Seconds 3600 }
29+
30+
imagePullPolicy: IfNotPresent
31+
volumeMounts:
32+
- name: kube-path
33+
mountPath: C:\k
34+
lifecycle:
35+
preStop:
36+
exec:
37+
command:
38+
- powershell.exe
39+
- -Command
40+
- "pktmon stop;sleep 20"
41+
volumes:
42+
- name: kube-path
43+
hostPath:
44+
path: C:\k
45+
nodeSelector:
46+
kubernetes.azure.com/os-sku: Windows2022
47+
tolerations:
48+
- effect: NoSchedule
49+
key: ipv6pilot
50+
operator: Exists

0 commit comments

Comments
 (0)