diff --git a/debug/windows/npm/README.md b/debug/windows/npm/README.md new file mode 100644 index 0000000000..2286a6be9b --- /dev/null +++ b/debug/windows/npm/README.md @@ -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 -n `) and run `.\win-debug.ps1`. The script will create a new folder called logs_DATE containing the results. \ No newline at end of file diff --git a/debug/windows/npm/pod_exec.ps1 b/debug/windows/npm/pod_exec.ps1 new file mode 100644 index 0000000000..9aa114d824 --- /dev/null +++ b/debug/windows/npm/pod_exec.ps1 @@ -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 diff --git a/debug/windows/npm/win-debug.ps1 b/debug/windows/npm/win-debug.ps1 new file mode 100644 index 0000000000..68f23f1043 --- /dev/null +++ b/debug/windows/npm/win-debug.ps1 @@ -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) { + $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 +}