Skip to content

Commit 8d7f888

Browse files
committed
Collect kube-apiserver logs from node
1 parent 3625700 commit 8d7f888

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/e2e/azure_logcollector.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ func linuxLogs(execToPathFn func(outputFileName string, command string, args ...
308308
"cni.log",
309309
"cat", "/var/log/calico/cni/cni.log",
310310
),
311+
// If kube-apiserver fails to come up, its logs aren't accessible via `kubectl logs`.
312+
// Grab them from the node instead.
313+
execToPathFn(
314+
"kube-apiserver.log",
315+
crictlPodLogsCmd("kube-apiserver"),
316+
),
311317
}
312318
}
313319

@@ -524,3 +530,13 @@ func writeBootLog(bootDiagnostics armcompute.RetrieveBootDiagnosticsDataResult,
524530

525531
return nil
526532
}
533+
534+
func crictlPodLogsCmd(podNamePattern string) string {
535+
//nolint: dupword // this is bash, not english
536+
return `sudo crictl pods --name "` + podNamePattern + `" -o json | jq -c '.items[]' | while read -r pod; do
537+
sudo crictl ps -a --pod $(jq -r .id <<< $pod) -o json | jq -c '.containers[]' | while read -r ctr; do
538+
echo "========= Pod $(jq -r .metadata.name <<< $pod), container $(jq -r .metadata.name <<< $ctr) ========="
539+
sudo crictl logs "$(jq -r .id <<< $ctr)" 2>&1
540+
done
541+
done`
542+
}

0 commit comments

Comments
 (0)