Skip to content

Commit 6afb540

Browse files
authored
add k8s log collector (#553)
1 parent 3d14d18 commit 6afb540

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ jobs:
9191
run: |
9292
source .venv/bin/activate
9393
./test/${{matrix.test}}
94+
- name: Collect Kubernetes logs
95+
if: always()
96+
run: |
97+
echo "Installing stern..."
98+
STERN_VERSION="1.30.0"
99+
curl -Lo stern.tar.gz https://github.com/stern/stern/releases/download/v${STERN_VERSION}/stern_${STERN_VERSION}_linux_amd64.tar.gz
100+
tar zxvf stern.tar.gz
101+
chmod +x stern
102+
sudo mv stern /usr/local/bin/
103+
104+
# Run script
105+
curl -O https://raw.githubusercontent.com/willcl-ark/warnet/main/resources/scripts/k8s-log-collector.sh
106+
chmod +x k8s-log-collector.sh
107+
./k8s-log-collector.sh default
108+
- name: Upload log artifacts
109+
if: always()
110+
uses: actions/upload-artifact@v4
111+
with:
112+
name: kubernetes-logs-${{ matrix.test }}
113+
path: ./k8s-logs
114+
retention-days: 5
94115
test-without-mk:
95116
runs-on: ubuntu-latest
96117
strategy:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Set variables
4+
NAMESPACE=${1:-default}
5+
LOG_DIR="./k8s-logs"
6+
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
7+
8+
# Ensure log directory exists
9+
mkdir -p "$LOG_DIR"
10+
11+
# Collect logs using stern (includes logs from terminated pods)
12+
echo "Collecting stern logs..."
13+
stern "(tank|commander).*" --namespace="$NAMESPACE" --output default --since 1h --no-follow > "$LOG_DIR/${TIMESTAMP}_stern_logs"
14+
15+
# Collect descriptions of all resources
16+
echo "Collecting resource descriptions..."
17+
kubectl describe all --namespace="$NAMESPACE" > "$LOG_DIR/${TIMESTAMP}_resource_descriptions.txt"
18+
19+
# Collect events
20+
echo "Collecting events..."
21+
kubectl get events --namespace="$NAMESPACE" --sort-by='.metadata.creationTimestamp' > "$LOG_DIR/${TIMESTAMP}_events.txt"
22+
23+
echo "Log collection complete. Logs saved in $LOG_DIR"

0 commit comments

Comments
 (0)