Skip to content

Commit b40ab29

Browse files
fix(cozyreport): portability and Ready-filter fixes from review
- Resolve hack/cozyreport-summary.sh via SCRIPT_DIR so cozyreport.sh can be invoked from any working directory, not only the repo root. - Discover Talos node IPs via `kubectl get nodes` (with the existing 192.168.123.11-13 list as fallback) instead of hardcoding the E2E sandbox topology. - Replace broken `awk '$NF != "True"'` filter on the cozystack-apps loop with a jsonpath check against the Ready condition; the previous filter compared AGE ("10m" etc.) against "True" and let every resource through, defeating the non-Ready filter. - Switch the Flux source CRD summary loop from column parsing to jsonpath (column positions differ between HelmRepository and OCIRepository printer columns) and add ExternalArtifact, matching what cozyreport.sh already collects. - Add `kubectl get crd` guards before HR/source CRD queries so the summary script does not abort under `set -eu` when Flux v2 is not installed. - Relabel "OOMKilled in last 30 min" to "Recent OOMKilled events (last 20)" — the kubectl call only limits count, not time. Surfaced from coderabbit and gemini review on #2553. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent aa72a23 commit b40ab29

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

‎hack/cozyreport-summary.sh‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ echo
1010

1111
echo "## HelmReleases not Ready"
1212
echo
13-
kubectl get hr -A --no-headers 2>/dev/null \
14-
| awk '$4 != "True" {printf " %s/%s — %s\n", $1, $2, $5}' \
15-
| head -40
13+
if kubectl get crd helmreleases.helm.toolkit.fluxcd.io >/dev/null 2>&1; then
14+
kubectl get hr -A --no-headers 2>/dev/null \
15+
| awk '$4 != "True" {printf " %s/%s — %s\n", $1, $2, $5}' \
16+
| head -40
17+
fi
1618
echo
1719

1820
echo "## Pods not Running/Succeeded"
@@ -28,7 +30,7 @@ kubectl get pod -A --no-headers 2>/dev/null \
2830
| awk '$4 ~ /ImagePullBackOff|ErrImagePull/ {printf " %s/%s — %s\n", $1, $2, $4}'
2931
echo
3032

31-
echo "## OOMKilled in last 30 min"
33+
echo "## Recent OOMKilled events (last 20)"
3234
echo
3335
kubectl get events -A --field-selector reason=OOMKilling --sort-by=.lastTimestamp 2>/dev/null \
3436
| tail -20
@@ -50,9 +52,10 @@ echo
5052

5153
echo "## Flux Sources not Ready"
5254
echo
53-
for kind in helmrepositories.source.toolkit.fluxcd.io ocirepositories.source.toolkit.fluxcd.io gitrepositories.source.toolkit.fluxcd.io; do
54-
kubectl get $kind -A --no-headers 2>/dev/null \
55-
| awk -v k="${kind%%.*}" '$4 != "True" {printf " %s %s/%s — Ready=%s\n", k, $1, $2, $4}'
55+
for kind in helmrepositories.source.toolkit.fluxcd.io ocirepositories.source.toolkit.fluxcd.io gitrepositories.source.toolkit.fluxcd.io externalartifacts.source.toolkit.fluxcd.io; do
56+
kubectl get crd "$kind" >/dev/null 2>&1 || continue
57+
short=${kind%%.*}
58+
kubectl get "$kind" -A -o jsonpath='{range .items[?(@.status.conditions[?(@.type=="Ready")].status!="True")]} '"$short"' {.metadata.namespace}/{.metadata.name} — Ready={.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}' 2>/dev/null
5659
done
5760
echo
5861

‎hack/cozyreport.sh‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
23
REPORT_DATE=$(date +%Y-%m-%d_%H-%M-%S)
34
REPORT_NAME=${1:-cozyreport-$REPORT_DATE}
45
REPORT_PDIR=$(mktemp -d)
@@ -140,8 +141,9 @@ for kind in applications.apps.cozystack.io applicationdefinitions.apps.cozystack
140141
short=${kind%%.*}
141142
if kubectl get crd $kind >/dev/null 2>&1; then
142143
kubectl get $kind -A > $DIR/$short.txt 2>&1
143-
kubectl get $kind -A --no-headers 2>/dev/null | awk 'NF >= 3 && $NF != "True" && $NF != "Ready"' | \
144-
while read NAMESPACE NAME _; do
144+
kubectl get $kind -A -o jsonpath='{range .items[?(@.status.conditions[?(@.type=="Ready")].status!="True")]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}' 2>/dev/null | \
145+
while read NAMESPACE NAME; do
146+
[ -z "$NAMESPACE" ] && continue
145147
d=$DIR/$short/$NAMESPACE/$NAME
146148
mkdir -p $d
147149
kubectl get $kind -n $NAMESPACE $NAME -o yaml > $d/$short.yaml 2>&1
@@ -241,17 +243,19 @@ free -m > $DIR/free.txt 2>&1
241243
ps auxww > $DIR/ps.txt 2>&1
242244
dmesg | tail -200 > $DIR/dmesg.txt 2>&1 || true
243245
if [ -f /workspace/talosconfig ]; then
244-
for node in 192.168.123.11 192.168.123.12 192.168.123.13; do
245-
talosctl --talosconfig /workspace/talosconfig -n $node dmesg --tail=200 > $DIR/talos-$node-dmesg.txt 2>&1 || true
246-
talosctl --talosconfig /workspace/talosconfig -n $node logs kubelet --tail=500 > $DIR/talos-$node-kubelet.log 2>&1 || true
247-
talosctl --talosconfig /workspace/talosconfig -n $node logs containerd --tail=500 > $DIR/talos-$node-containerd.log 2>&1 || true
246+
NODES=$(kubectl get nodes -o jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address}{"\n"}{end}' 2>/dev/null)
247+
for node in ${NODES:-192.168.123.11 192.168.123.12 192.168.123.13}; do
248+
[ -z "$node" ] && continue
249+
talosctl --talosconfig /workspace/talosconfig -n "$node" dmesg --tail=200 > "$DIR/talos-$node-dmesg.txt" 2>&1 || true
250+
talosctl --talosconfig /workspace/talosconfig -n "$node" logs kubelet --tail=500 > "$DIR/talos-$node-kubelet.log" 2>&1 || true
251+
talosctl --talosconfig /workspace/talosconfig -n "$node" logs containerd --tail=500 > "$DIR/talos-$node-containerd.log" 2>&1 || true
248252
done
249253
fi
250254

251255
# -- finalization
252256

253257
echo "Generating summary..."
254-
hack/cozyreport-summary.sh > $REPORT_DIR/summary.txt 2>&1 || true
258+
"$SCRIPT_DIR/cozyreport-summary.sh" > "$REPORT_DIR/summary.txt" 2>&1 || true
255259

256260
echo "Creating archive..."
257261
tar -czf $REPORT_NAME.tgz -C $REPORT_PDIR .

0 commit comments

Comments
 (0)