Skip to content

Commit bfcf273

Browse files
tool: [WIN-NPM] minor updates to windows script, and new linux script (#1685)
* minor fixes to win-debug.ps1 and same script for linux * delete previous results when rerunning pod_exec.ps1 * fix filename that we copy from
1 parent 5e93d4a commit bfcf273

File tree

4 files changed

+86
-10
lines changed

4 files changed

+86
-10
lines changed

debug/windows/npm/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
This script will collect Windows NPM logs and the HNS and VFP state of the cluster and write them to a new local folder.
44

55
## How to collect logs
6+
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>`)
7+
### Windows
8+
Run `.\win-debug.ps1`. The script will create a new folder called logs_DATE containing the results.
69

7-
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.
10+
### Linux
11+
Run `.\win-debug.sh`. The script will create a new folder called logs_DATE containing the results.
12+
13+
Note: You may not be able to unzip logs.zip in Linux since it was compressed in Windows.

debug/windows/npm/pod_exec.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
param([string]$podIps)
2-
$filepath = "logs"
2+
$filepath = "npm-exec-logs"
3+
4+
Write-Output "attempting to delete previous results if they exist"
5+
Remove-Item -path $filepath -recurse
36

47
$podIp = @()
58
foreach ($r in ($podIps -split " ")) {
@@ -21,6 +24,6 @@ foreach ($r in ($podIps -split " ")) {
2124
}
2225
}
2326

24-
Compress-Archive -Path 'logs' -DestinationPath 'logs.zip' -Force
27+
Compress-Archive -Path "$filepath" -DestinationPath "$filepath.zip" -Force
2528

2629
exit

debug/windows/npm/win-debug.ps1

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
$filepath = "logs_$((Get-Date).ToString('MM-dd-yyyy'))"
2-
kubectl get pod -A -o wide >> ( New-Item -Path ./$filepath/allpods.out -Force )
2+
Write-Output "gathering logs and writing to $filepath/"
3+
4+
kubectl get pod -A -o wide --show-labels > ( New-Item -Path ./$filepath/allpods.out -Force )
5+
kubectl get netpol -A -o yaml > ( New-Item -Path ./$filepath/all-netpol-yamls.out -Force )
6+
kubectl describe netpol -A > ( New-Item -Path ./$filepath/all-netpol-descriptions.out -Force )
7+
38
$npmpod = kubectl get pod -n kube-system -owide --output=custom-columns='Name:.metadata.name,Node:spec.nodeName' | Select-String "npm-win"
49
$rows = @()
510
foreach ($row in (-split $npmpod)) {
@@ -10,9 +15,10 @@ for ($i = 0; $i -lt $rows.Length; $i += 2) {
1015
$npm = $rows[$i]
1116
$node = $rows[$i + 1]
1217

13-
Write-Output "Gathering logs for node $node"
18+
Write-Output "Gathering logs. npm pod: $npm. node: $node"
19+
kubectl logs -n kube-system $npm > $filepath/logs_$npm.out
1420

15-
$ip = kubectl get pod -n kube-system -owide --output=custom-columns='IP:.status.podIP,Node:spec.nodeName' | Select-String "$node"
21+
$ip = kubectl get pod -A -owide --output=custom-columns='IP:.status.podIP,Node:spec.nodeName' | Select-String "$node"
1622
$ip = (-split $ip)
1723
[string] $ips = ""
1824
for ($j = 0; $j -lt $ip.Length; $j += 2) {
@@ -21,10 +27,17 @@ for ($i = 0; $i -lt $rows.Length; $i += 2) {
2127
else{
2228
$ips += $ip[$j]
2329
}
24-
}
25-
26-
kubectl logs -n kube-system $npm >> $filepath/logs_$npm.out
30+
}
31+
echo "node $node has IPs: $ips"
32+
33+
Write-Output "copying ps1 file into $npm"
2734
kubectl cp ./pod_exec.ps1 kube-system/"$npm":execw.ps1
35+
36+
Write-Output echo "executing ps1 file on $npm"
2837
kubectl exec -it -n kube-system $npm -- powershell.exe -Command .\execw.ps1 "'$ips'"
29-
kubectl cp kube-system/"$npm":logs.zip ./$filepath/logs_$node.zip
38+
39+
Write-Output "copying logs.zip from $npm"
40+
kubectl cp kube-system/"$npm":npm-exec-logs.zip ./$filepath/npm-exec-logs_$node.zip
3041
}
42+
43+
Write-Output "finished capturing all logs. written to $filepath/"

debug/windows/npm/win-debug.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# NOTE: you may not be able to unzip logs.zip in Linux since it was compressed in Windows
2+
set -e
3+
dateString=`date -I` # like 2022-09-24
4+
filepath=logs_$dateString
5+
mkdir $filepath
6+
7+
echo "gathering logs and writing to $filepath/"
8+
9+
kubectl get pod -A -o wide --show-labels > $filepath/allpods.out
10+
kubectl get netpol -A -o yaml > $filepath/all-netpol-yamls.out
11+
kubectl describe netpol -A > $filepath/all-netpol-descriptions.out
12+
13+
npmPods=()
14+
nodes=()
15+
for npmPodOrNode in `kubectl get pod -n kube-system -owide --output=custom-columns='Name:.metadata.name,Node:spec.nodeName' | grep "npm-win"`; do
16+
# for loop will go over each item (npm pod, then its node, then the next npm pod, then its node, ...)
17+
set +e
18+
echo $npmPodOrNode | grep -q azure-npm-win-
19+
if [ $? -eq 0 ]; then
20+
npmPods+=($npmPodOrNode)
21+
else
22+
nodes+=($npmPodOrNode)
23+
fi
24+
done
25+
set -e
26+
27+
echo "npm pods: ${npmPods[@]}"
28+
echo "nodes of npm pods: ${nodes[@]}"
29+
30+
for i in $(seq 1 ${#npmPods[*]}); do
31+
j=$((i-1))
32+
npmPod=${npmPods[$j]}
33+
node=${nodes[$j]}
34+
35+
echo "gathering logs. npm pod: $npmPod. node: $node"
36+
kubectl logs -n kube-system $npmPod > $filepath/logs_$npmPod.out
37+
38+
ips=()
39+
for ip in `kubectl get pod -A -owide --output=custom-columns='IP:.status.podIP,Node:spec.nodeName' | grep $node | grep -oP "\d+\.\d+\.\d+\.\d+"`; do
40+
ips+=($ip)
41+
done
42+
echo "node $node has IPs: ${ips[@]}"
43+
44+
echo "copying ps1 file into $npmPod"
45+
kubectl cp ./pod_exec.ps1 kube-system/"$npmPod":execw.ps1
46+
47+
echo "executing ps1 file on $npmPod"
48+
kubectl exec -it -n kube-system $npmPod -- powershell.exe -Command .\\execw.ps1 "'${ips[@]}'"
49+
50+
echo "copying logs.zip from $npmPod. NOTE: this will be a windows-based compressed archive (probably need windows to expand it)"
51+
kubectl cp kube-system/"$npmPod":npm-exec-logs.zip $filepath/npm-exec-logs_$node.zip
52+
done
53+
54+
echo "finished gathering all logs. written to $filepath/"

0 commit comments

Comments
 (0)