mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
testops: add k8s failure snapshot helper
This commit is contained in:
1 parent
b8cf3e3f67
commit
5fe469c3a4
3 files changed
+132
-1
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# Current Plan: Phase 33 - TestOps Failure Hardening
|
||||
|
||||
Status: active, 20% complete. Started on 2026-05-27.
|
||||
Status: active, 30% complete. Started on 2026-05-27.
|
||||
|
||||
Branch: `phase33-testops-failure-hardening`
|
||||
|
||||
@@ -78,6 +78,12 @@ no broad HA claim added
|
||||
|
||||
Goal: reduce shell gymnastics and make failed runs self-explaining.
|
||||
|
||||
Status: in progress, first helper landed.
|
||||
|
||||
Artifact:
|
||||
|
||||
- `scripts/collect-k8s-failure-snapshot.sh`
|
||||
|
||||
P0 items:
|
||||
|
||||
- Add or standardize failure snapshot capture.
|
||||
@@ -174,5 +180,7 @@ release claims updated or explicitly unchanged
|
||||
- 5%: branch created from merged `main`.
|
||||
- 5%: `AGENTS.md` added to guide future agent behavior.
|
||||
- 10%: Phase 33 scope, D1-D5 gates, and roadmap pointers drafted.
|
||||
- 20%: D1 failure matrix drafted.
|
||||
- 30%: D2 failure snapshot helper and contract test added.
|
||||
|
||||
Next step: D2 runner/helper hardening for the P0 gates.
|
||||
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="${1:-$(pwd)}"
|
||||
ARTIFACT_DIR="${SW_BLOCK_FAILURE_SNAPSHOT_OUT:-${SW_BLOCK_ARTIFACT_DIR:-/tmp/sw-block-failure-snapshot-$(date -u +%Y%m%dT%H%M%SZ)}}"
|
||||
NAMESPACE="${SW_BLOCK_APP_NAMESPACE:-default}"
|
||||
HELM_NAMESPACE="${SW_BLOCK_HELM_NAMESPACE:-kube-system}"
|
||||
HELM_RELEASE="${SW_BLOCK_HELM_RELEASE:-sw-block}"
|
||||
IQN_SUBSTR="${SW_BLOCK_FAILURE_SNAPSHOT_IQN_SUBSTR:-io.seaweedfs}"
|
||||
|
||||
mkdir -p "$ARTIFACT_DIR"/{k8s,logs,host,helm}
|
||||
|
||||
if [[ -z "${KUBECONFIG:-}" && -f /etc/rancher/k3s/k3s.yaml ]]; then
|
||||
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
||||
fi
|
||||
|
||||
capture_failures=0
|
||||
|
||||
capture() {
|
||||
local out="$1"
|
||||
shift
|
||||
if ! "$@" >"$out" 2>&1; then
|
||||
capture_failures=$((capture_failures + 1))
|
||||
{
|
||||
echo
|
||||
echo "[failure-snapshot] command failed: $*"
|
||||
} >>"$out"
|
||||
fi
|
||||
}
|
||||
|
||||
capture_optional_sudo() {
|
||||
local out="$1"
|
||||
shift
|
||||
if command -v sudo >/dev/null 2>&1 && sudo -n true >/dev/null 2>&1; then
|
||||
capture "$out" sudo -n "$@"
|
||||
else
|
||||
capture "$out" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
capture "$ARTIFACT_DIR/helm/status.txt" helm status "$HELM_RELEASE" --namespace "$HELM_NAMESPACE"
|
||||
capture "$ARTIFACT_DIR/helm/list.txt" helm list --all-namespaces
|
||||
capture "$ARTIFACT_DIR/helm/values.txt" helm get values "$HELM_RELEASE" --namespace "$HELM_NAMESPACE" --all
|
||||
|
||||
capture "$ARTIFACT_DIR/k8s/nodes.txt" kubectl get nodes -o wide
|
||||
capture "$ARTIFACT_DIR/k8s/kube-system.txt" kubectl -n "$HELM_NAMESPACE" get pods,deploy,daemonset,svc,configmap,secret -o wide
|
||||
capture "$ARTIFACT_DIR/k8s/app-namespace.txt" kubectl -n "$NAMESPACE" get pods,deploy,pvc,pv -o wide
|
||||
capture "$ARTIFACT_DIR/k8s/pods-all.yaml" kubectl get pods -A -o yaml
|
||||
capture "$ARTIFACT_DIR/k8s/pvc-all.yaml" kubectl get pvc -A -o yaml
|
||||
capture "$ARTIFACT_DIR/k8s/volumeattachments.yaml" kubectl get volumeattachments -o yaml
|
||||
capture "$ARTIFACT_DIR/k8s/events-all.txt" kubectl get events -A --sort-by=.lastTimestamp
|
||||
capture "$ARTIFACT_DIR/k8s/sw-block-resources.txt" bash -c "kubectl get deploy,daemonset,statefulset,pod,svc,pvc,pv,configmap,secret,serviceaccount -A -o name; kubectl get storageclass,csidriver,clusterrole,clusterrolebinding -o name"
|
||||
|
||||
capture "$ARTIFACT_DIR/k8s/blockvolume-deployments.yaml" kubectl -n "$NAMESPACE" get deploy -l app=sw-blockvolume -o yaml
|
||||
capture "$ARTIFACT_DIR/k8s/blockvolume-pods.yaml" kubectl -n "$NAMESPACE" get pods -l app=sw-blockvolume -o yaml
|
||||
capture "$ARTIFACT_DIR/k8s/app-pods-describe.txt" kubectl -n "$NAMESPACE" describe pods
|
||||
capture "$ARTIFACT_DIR/k8s/kube-system-pods-describe.txt" kubectl -n "$HELM_NAMESPACE" describe pods
|
||||
|
||||
capture "$ARTIFACT_DIR/logs/blockmaster.current.log" kubectl -n "$HELM_NAMESPACE" logs deploy/sw-blockmaster --all-containers --tail=500
|
||||
capture "$ARTIFACT_DIR/logs/blockmaster.previous.log" kubectl -n "$HELM_NAMESPACE" logs deploy/sw-blockmaster --all-containers --previous --tail=500
|
||||
capture "$ARTIFACT_DIR/logs/csi-controller.current.log" kubectl -n "$HELM_NAMESPACE" logs deploy/sw-block-csi-controller --all-containers --tail=500
|
||||
capture "$ARTIFACT_DIR/logs/csi-controller.previous.log" kubectl -n "$HELM_NAMESPACE" logs deploy/sw-block-csi-controller --all-containers --previous --tail=500
|
||||
capture "$ARTIFACT_DIR/logs/csi-node.current.log" kubectl -n "$HELM_NAMESPACE" logs ds/sw-block-csi-node --all-containers --tail=500
|
||||
capture "$ARTIFACT_DIR/logs/csi-node.previous.log" kubectl -n "$HELM_NAMESPACE" logs ds/sw-block-csi-node --all-containers --previous --tail=500
|
||||
capture "$ARTIFACT_DIR/logs/blockvolume.current.log" kubectl -n "$NAMESPACE" logs -l app=sw-blockvolume --all-containers --tail=500
|
||||
capture "$ARTIFACT_DIR/logs/blockvolume.previous.log" kubectl -n "$NAMESPACE" logs -l app=sw-blockvolume --all-containers --previous --tail=500
|
||||
|
||||
capture_optional_sudo "$ARTIFACT_DIR/host/iscsi-sessions.txt" iscsiadm -m session
|
||||
capture_optional_sudo "$ARTIFACT_DIR/host/iscsi-nodes.txt" iscsiadm -m node
|
||||
capture_optional_sudo "$ARTIFACT_DIR/host/multipath.txt" multipath -ll
|
||||
capture_optional_sudo "$ARTIFACT_DIR/host/dmsetup.txt" dmsetup ls --tree
|
||||
capture "$ARTIFACT_DIR/host/kubelet-mounts.txt" findmnt -R /var/lib/kubelet -o TARGET,SOURCE,FSTYPE,OPTIONS
|
||||
capture "$ARTIFACT_DIR/host/processes.txt" ps -eo pid,args
|
||||
|
||||
{
|
||||
if [[ "$capture_failures" -eq 0 ]]; then
|
||||
echo "failure_snapshot_status=ok"
|
||||
else
|
||||
echo "failure_snapshot_status=partial"
|
||||
fi
|
||||
echo "capture_failure_count=$capture_failures"
|
||||
echo "namespace=$NAMESPACE"
|
||||
echo "helm_namespace=$HELM_NAMESPACE"
|
||||
echo "helm_release=$HELM_RELEASE"
|
||||
echo "iqn_substr=$IQN_SUBSTR"
|
||||
echo "read_only=true"
|
||||
echo "k8s_snapshot=k8s"
|
||||
echo "logs=logs"
|
||||
echo "host_snapshot=host"
|
||||
} >"$ARTIFACT_DIR/failure-snapshot-summary.txt"
|
||||
|
||||
cat "$ARTIFACT_DIR/failure-snapshot-summary.txt"
|
||||
@@ -28,6 +28,37 @@ func TestUninstallK8sAlphaDeletesSeaweedISCSINodeRecords(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailureSnapshotScriptCapturesRequiredEvidenceLayers(t *testing.T) {
|
||||
root := repoRoot(t)
|
||||
raw, err := os.ReadFile(filepath.Join(root, "scripts", "collect-k8s-failure-snapshot.sh"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
script := string(raw)
|
||||
for _, want := range []string{
|
||||
"failure_snapshot_status=",
|
||||
"capture_failure_count=",
|
||||
"k8s/pods-all.yaml",
|
||||
"k8s/events-all.txt",
|
||||
"k8s/blockvolume-deployments.yaml",
|
||||
"k8s/app-pods-describe.txt",
|
||||
"logs/blockmaster.current.log",
|
||||
"logs/blockmaster.previous.log",
|
||||
"logs/csi-node.current.log",
|
||||
"logs/csi-node.previous.log",
|
||||
"host/iscsi-sessions.txt",
|
||||
"host/iscsi-nodes.txt",
|
||||
"host/multipath.txt",
|
||||
"host/dmsetup.txt",
|
||||
"host/processes.txt",
|
||||
"read_only=true",
|
||||
} {
|
||||
if !strings.Contains(script, want) {
|
||||
t.Fatalf("failure snapshot script missing %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func repoRoot(t *testing.T) string {
|
||||
t.Helper()
|
||||
dir, err := os.Getwd()
|
||||
|
||||
Reference in new issue
Block a user