From 3cf7cb7d77014de6cc86b183cd88289b1e14df0b Mon Sep 17 00:00:00 2001 From: ShiqianTao Date: Tue, 19 Dec 2023 16:25:58 +0800 Subject: [PATCH 1/2] feat: collect kubectl information in AKS Windows node log --- .../windows/debug/collect-windows-logs.ps1 | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/staging/cse/windows/debug/collect-windows-logs.ps1 b/staging/cse/windows/debug/collect-windows-logs.ps1 index 04c341761f3..b974f88bc59 100644 --- a/staging/cse/windows/debug/collect-windows-logs.ps1 +++ b/staging/cse/windows/debug/collect-windows-logs.ps1 @@ -330,6 +330,38 @@ if (Test-Path $nvidiaInstallLogFolder) { } } +if ((Test-Path "c:\k\kubectl.exe") -and (Test-Path "c:\k\config")) { + try { + Write-Host "Collecting the information of the node and pods by kubectl" + function kubectl { c:\k\kubectl.exe --kubeconfig c:\k\config $args } + + $testResult = kubectl version 2>&1 + if ($LASTEXITCODE -ne 0) { + throw "Failed to run kubectl, result: $testResult" + } + + kubectl get nodes -o wide > "$ENV:TEMP\kubectl-get-nodes-$($timeStamp).log" + + $nodeName = $env:COMPUTERNAME.ToLower() + kubectl describe node $nodeName > "$ENV:TEMP\kubectl-describe-nodes-$($timeStamp).log" + + $podsJson = & crictl.exe pods --output json | ConvertFrom-Json + foreach ($pod in $podsJson.items) { + $podName = $pod.metadata.name + $namespace = $pod.metadata.namespace + kubectl describe pod $podName -n $namespace >> "$ENV:TEMP\kubectl-describe-pods-$($timeStamp).log" + } + + $kubectlLogFiles = Get-ChildItem -Path "$ENV:TEMP\kubectl-*.log" + foreach ($kFile in $kubectlLogFiles) { + $paths += $kFile.FullName + } + } + catch { + Write-Host "Error: $_" + } +} + Write-Host "All logs collected: $paths" Stop-Transcript From e82f7f9a16151d91052995af3e442bee724571aa Mon Sep 17 00:00:00 2001 From: ShiqianTao Date: Wed, 20 Dec 2023 09:48:41 +0800 Subject: [PATCH 2/2] chore: add log file path one by one --- .../cse/windows/debug/collect-windows-logs.ps1 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/staging/cse/windows/debug/collect-windows-logs.ps1 b/staging/cse/windows/debug/collect-windows-logs.ps1 index b974f88bc59..1b01c8b4475 100644 --- a/staging/cse/windows/debug/collect-windows-logs.ps1 +++ b/staging/cse/windows/debug/collect-windows-logs.ps1 @@ -340,22 +340,21 @@ if ((Test-Path "c:\k\kubectl.exe") -and (Test-Path "c:\k\config")) { throw "Failed to run kubectl, result: $testResult" } - kubectl get nodes -o wide > "$ENV:TEMP\kubectl-get-nodes-$($timeStamp).log" + kubectl get nodes -o wide > "$ENV:TEMP\kubectl-get-nodes.log" + $paths += "$ENV:TEMP\kubectl-get-nodes.log" $nodeName = $env:COMPUTERNAME.ToLower() - kubectl describe node $nodeName > "$ENV:TEMP\kubectl-describe-nodes-$($timeStamp).log" + kubectl describe node $nodeName > "$ENV:TEMP\kubectl-describe-nodes.log" + $paths += "$ENV:TEMP\kubectl-describe-nodes.log" + "kubectl describe all pods on $nodeName" > "$ENV:TEMP\kubectl-describe-pods.log" $podsJson = & crictl.exe pods --output json | ConvertFrom-Json foreach ($pod in $podsJson.items) { $podName = $pod.metadata.name $namespace = $pod.metadata.namespace - kubectl describe pod $podName -n $namespace >> "$ENV:TEMP\kubectl-describe-pods-$($timeStamp).log" - } - - $kubectlLogFiles = Get-ChildItem -Path "$ENV:TEMP\kubectl-*.log" - foreach ($kFile in $kubectlLogFiles) { - $paths += $kFile.FullName + kubectl describe pod $podName -n $namespace >> "$ENV:TEMP\kubectl-describe-pods.log" # append } + $paths += "$ENV:TEMP\kubectl-describe-pods.log" } catch { Write-Host "Error: $_"