-
Notifications
You must be signed in to change notification settings - Fork 8
Scripts to identify if the compartmentid in endpoint info and corresponding namespace info is different. #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
princepereira
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
princepereira:user/ppereira/invalidCompartment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 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. | ||
|
|
||
| To run the script, open a PowerShell window and run the following command: | ||
| PS> .\invalidCompartment.ps1 | ||
|
|
||
| Or, we can run the scripts under hostprocess daemonset containers using invalidCompartment.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| function Is-CompartmentIdValid() { | ||
| Write-Host "#===== Validating Compartment ID in Endpoint and Namespace =====#" | ||
| Write-Host "" | ||
| $eps = Get-HnsEndpoint | ||
| $nss = Get-HnsNamespace | ||
| $compsNotMatching = @() | ||
|
|
||
| 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..." | ||
| $compsNotMatching += $ep.IPAddress | ||
| } else { | ||
| Write-Host "CompartmentId matching..." | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Write-Host "" | ||
| if ($compsNotMatching.Length -gt 0) { | ||
| Write-Host "CompartmentId not matching for the following IPs: $($compsNotMatching -join ', ')" -ForegroundColor Red | ||
| return $false | ||
| } | ||
| return $true | ||
| } | ||
|
|
||
| $iter = 1 | ||
| $curLoc = (Get-Location).Path | ||
| pktmon stop # Stopping if pktmon is already running | ||
|
|
||
| # Start pktmon | ||
| 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 "" | ||
| # Stop pktmon | ||
| pktmon stop | ||
|
|
||
| # Collecting Windows logs | ||
| C:\k\debug\collect-windows-logs.ps1 | ||
|
|
||
| Write-Host "Traces available in $curLoc\traces.etl" | ||
|
|
||
| # The below While loop will keep the script running indefinitely keeping the hpc pod alive. | ||
| # Without this, the pod will exit after the script execution and restart the process again deleting the logs. | ||
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| apiVersion: apps/v1 | ||
| kind: DaemonSet | ||
| metadata: | ||
| name: invalidcompartment | ||
| labels: | ||
| app: invalidcompartment | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| name: invalidcompartment | ||
| template: | ||
| metadata: | ||
| labels: | ||
| name: invalidcompartment | ||
| spec: | ||
| securityContext: | ||
| windowsOptions: | ||
| hostProcess: true | ||
| runAsUserName: "NT AUTHORITY\\SYSTEM" | ||
| hostNetwork: true | ||
| containers: | ||
| - name: invalidcompartment | ||
| image: mcr.microsoft.com/dotnet/framework/samples:aspnetapp | ||
| command: | ||
| - powershell.exe | ||
| - -command | ||
| - | | ||
| function Is-CompartmentIdValid { Write-Host "#===== Validating Compartment ID in Endpoint and Namespace =====#"; Write-Host ""; $eps = Get-HnsEndpoint; $nss = Get-HnsNamespace; $compsNotMatching = @(); 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..."; $compsNotMatching += $ep.IPAddress } else { Write-Host "CompartmentId matching..." } } } } } if ($compsNotMatching.Length -gt 0) { Write-Host "CompartmentId not matching for the following IPs: $($compsNotMatching -join ', ')" -ForegroundColor Red ; return $false } 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 } | ||
|
|
||
| imagePullPolicy: IfNotPresent | ||
| volumeMounts: | ||
| - name: kube-path | ||
| mountPath: C:\k | ||
| lifecycle: | ||
| preStop: | ||
| exec: | ||
| command: | ||
| - powershell.exe | ||
| - -Command | ||
| - "pktmon stop;sleep 20" | ||
| volumes: | ||
| - name: kube-path | ||
| hostPath: | ||
| path: C:\k | ||
| nodeSelector: | ||
| kubernetes.azure.com/os-sku: Windows2022 | ||
| tolerations: | ||
| - effect: NoSchedule | ||
| key: ipv6pilot | ||
| operator: Exists |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.