Skip to content
Merged
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
7 changes: 7 additions & 0 deletions debug/windows/npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Introduction

This script will collect Windows NPM logs and the HNS and VFP state of the cluster and write them to a new local folder.

## How to collect logs

In a PowerShell terminal, navigate to the `azure-container-networking/debug/windows/npm folder`. Make sure your kubectl is configured to point to the cluster you want to collect logs from (`az aks get-credentials -g <resource-group> -n <cluster-name>`) and run `.\win-debug.ps1`. The script will create a new folder called logs_DATE containing the results.
26 changes: 26 additions & 0 deletions debug/windows/npm/pod_exec.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
param([string]$podIps)
$filepath = "logs"

$podIp = @()
foreach ($r in ($podIps -split " ")) {
$podIp += $r
}

(Get-HnsNetwork | ? Name -Like azure).Policies >>( New-Item -Path ./$filepath/hns_state.out -Force )
Get-HnsEndpoint | ConvertTo-Json >> $filepath/hns_state.out


foreach ($row in $podIp) {
Write-Output "Gathering logs for IP $row"
[string]$endpoint = hnsdiag list endpoints | select-string -context 2, 0 "$row"
if($endpoint -ne $null){
$endpointID = $endpoint.Substring($endpoint.IndexOf(":")+2,37).Trim()
hnsdiag list endpoints | select-string -context 2, 0 "$row" >> $filepath/vfp_state_$row.out
vfpctrl /port $endpointID /list-tag >> $filepath/vfp_state_$row.out
vfpctrl /port $endpointID /layer ACL_ENDPOINT_LAYER /list-rule >> $filepath/vfp_state_$row.out
}
}

Compress-Archive -Path 'logs' -DestinationPath 'logs.zip' -Force

exit
30 changes: 30 additions & 0 deletions debug/windows/npm/win-debug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$filepath = "logs_$((Get-Date).ToString('MM-dd-yyyy'))"
kubectl get pod -A -o wide >> ( New-Item -Path ./$filepath/allpods.out -Force )
$npmpod = kubectl get pod -n kube-system -owide --output=custom-columns='Name:.metadata.name,Node:spec.nodeName' | Select-String "npm-win"
$rows = @()
foreach ($row in (-split $npmpod)) {
$rows += $row
}

for ($i = 0; $i -lt $rows.Length; $i += 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add some prints to add some info on what it is collecting, where it is storing etc , so that the script does not feel stuck

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

$npm = $rows[$i]
$node = $rows[$i + 1]

Write-Output "Gathering logs for node $node"

$ip = kubectl get pod -n kube-system -owide --output=custom-columns='IP:.status.podIP,Node:spec.nodeName' | Select-String "$node"
$ip = (-split $ip)
[string] $ips = ""
for ($j = 0; $j -lt $ip.Length; $j += 2) {
if($j -ne $ip.Length-2){
$ips += $ip[$j] + " "}
else{
$ips += $ip[$j]
}
}

kubectl logs -n kube-system $npm >> $filepath/logs_$npm.out
kubectl cp ./pod_exec.ps1 kube-system/"$npm":execw.ps1
kubectl exec -it -n kube-system $npm -- powershell.exe -Command .\execw.ps1 "'$ips'"
kubectl cp kube-system/"$npm":logs.zip ./$filepath/logs_$node.zip
}