Skip to content

Commit 15704ac

Browse files
committed
Adding logic to get pod logs form windows nodes during ci-entrypoint.sh
1 parent 04cba22 commit 15704ac

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: log-dump-node-windows
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: log-dump-node-windows
9+
template:
10+
metadata:
11+
labels:
12+
app:
13+
log-dump-node-windows
14+
spec:
15+
securityContext:
16+
windowsOptions:
17+
runAsUserName: ContainerAdministrator
18+
containers:
19+
- name: log-dump-node-windows
20+
image: mcr.microsoft.com/oss/kubernetes/pause:3.6
21+
volumeMounts:
22+
- name: varlog
23+
mountPath: /var/log
24+
nodeSelector:
25+
kubernetes.io/os: windows
26+
tolerations:
27+
- effect: NoExecute
28+
operator: Exists
29+
- effect: NoSchedule
30+
operator: Exists
31+
- key: CriticalAddonsOnly
32+
operator: Exists
33+
volumes:
34+
- name: varlog
35+
hostPath:
36+
path: /var/log

hack/log/log-dump.sh

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,52 @@ dump_workload_cluster_logs() {
127127
wait
128128
}
129129

130+
dump_workload_cluster_logs_windows() {
131+
echo "Deploying log-dump-daemonset-windows"
132+
"${KUBECTL}" apply -f "${REPO_ROOT}/hack/log/log-dump-daemonset-windows.yaml"
133+
echo "Waiting for log-dump-daemonset-windows"
134+
"${KUBECTL}" wait pod -l app=log-dump-node-windows --for=condition=Ready --timeout=5m
135+
136+
IFS=" " read -ra log_dump_pods <<< "$(kubectl get pod -l app=log-dump-node-windows -ojsonpath='{.items[*].metadata.name}')"
137+
138+
for log_dump_pod in "${log_dump_pods[@]}"; do
139+
local node_name
140+
node_name="$(get_node_name "${log_dump_pod}")"
141+
echo "Getting logs for node ${node_name}"
142+
143+
local log_dump_dir="${ARTIFACTS}/workload-cluster/${node_name}"
144+
mkdir -p "${log_dump_dir}"
145+
146+
# make a new folder to copy logs to since files cannot be read to directly
147+
"${KUBECTL}" exec "${log_dump_pod}" -- cmd.exe /c mkdir log
148+
"${KUBECTL}" exec "${log_dump_pod}" -- cmd.exe /c xcopy /s c:\\var\\log\\kubelet c:\\log\\
149+
"${KUBECTL}" exec "${log_dump_pod}" -- cmd.exe /c xcopy /s c:\\var\\log\\pods c:\\log\\
150+
151+
# Get a list of all of the files to copy with dir
152+
# /s - recurse
153+
# /B - bare format (no heading info or summaries)
154+
# /A-D - exclude directories
155+
IFS=" " read -ra log_dump_files <<< "$(kubectl exec "${log_dump_pod}" -- cmd.exe /c dir /s /B /A-D log | tr '\n' ' ' | tr -d '\r' )"
156+
echo "Collecting pod logs"
157+
158+
for log_dump_file in "${log_dump_files[@]}"; do
159+
echo " Getting logfile ${log_dump_file}"
160+
# reverse slashes and remove c:\log\ from paths
161+
fixed_dump_file_path="$(echo "${log_dump_file//\\//}" | cut -d "/" -f3-)"
162+
dir="$(dirname "${fixed_dump_file_path}")"
163+
file="$(basename "${fixed_dump_file_path}")"
164+
mkdir -p "${log_dump_dir}"/"${dir}"
165+
"${KUBECTL}" exec "${log_dump_pod}" -- cmd.exe /c type "${log_dump_file}" > "${log_dump_dir}"/"${dir}"/"${file}"
166+
done
167+
168+
echo "Exported logs for node \"${node_name}\""
169+
done
170+
171+
}
172+
130173
cleanup() {
131174
"${KUBECTL}" delete -f "${REPO_ROOT}/hack/log/log-dump-daemonset.yaml" || true
175+
"${KUBECTL}" delete -f "${REPO_ROOT}/hack/log/log-dump-daemonset-windows.yaml" || true
132176
# shellcheck source=hack/log/redact.sh
133177
source "${REPO_ROOT}/hack/log/redact.sh"
134178
}
@@ -138,5 +182,12 @@ trap cleanup EXIT
138182
echo "================ DUMPING LOGS FOR MANAGEMENT CLUSTER ================"
139183
dump_mgmt_cluster_logs
140184

141-
echo "================ DUMPING LOGS FOR WORKLOAD CLUSTER ================"
185+
echo "================ DUMPING LOGS FOR WORKLOAD CLUSTER (Linux) =========="
142186
dump_workload_cluster_logs
187+
188+
if [[ -z "${TEST_WINDOWS}" ]]; then
189+
echo "TEST_WINDOWS envvar not set, skipping log collection for Windows nodes."
190+
else
191+
echo "================ DUMPING LOGS FOR WORKLOAD CLUSTER (Windows) ========"
192+
dump_workload_cluster_logs_windows
193+
fi

0 commit comments

Comments
 (0)