Skip to content

Commit b635e08

Browse files
authored
Merge pull request #5663 from nojnhuh/apiserver-logs
Collect kube-apiserver logs from node
2 parents 1d97b87 + 7c5e347 commit b635e08

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

hack/create-dev-cluster.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ capz::util::generate_ssh_key
6666
echo "================ DOCKER BUILD ==============="
6767
PULL_POLICY=IfNotPresent make modules docker-build
6868

69-
setup() {
69+
create_cluster() {
7070
echo "================ MAKE CLEAN ==============="
7171
make clean
7272

@@ -75,17 +75,14 @@ setup() {
7575

7676
echo "================ INSTALL TOOLS ==============="
7777
make install-tools
78-
}
7978

80-
create_cluster() {
8179
echo "================ CREATE CLUSTER ==============="
8280
make create-cluster
8381
}
8482

8583
retries=$CLUSTER_CREATE_ATTEMPTS
86-
while ((retries > 0)); do
87-
setup
88-
create_cluster && break
89-
sleep 5
90-
((retries --))
84+
until create_cluster; do
85+
if ((--retries == 0)); then
86+
exit 1
87+
fi
9188
done

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)