Skip to content

WIP : feat(support-bundle): add consolidated support-bundle.sh collector - #40

Open
brathina-spectro wants to merge 2 commits into
mainfrom
feat/consolidated-support-bundle
Open

WIP : feat(support-bundle): add consolidated support-bundle.sh collector#40
brathina-spectro wants to merge 2 commits into
mainfrom
feat/consolidated-support-bundle

Conversation

@brathina-spectro

@brathina-spectro brathina-spectro commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Consolidates support-bundle-edge.sh (host + cluster) and support-bundle-infra.sh (cluster-only) into a single capability-driven script, support-bundle.sh, per the consolidation design. The legacy scripts are kept intact as fallbacks until the consolidated script is widely adopted; they can be phased out later.

  • support-bundle.shsupport-bundle-edge.sh (full scope, root required)
  • support-bundle.sh -Hsupport-bundle-infra.sh (cluster-only, no root)

Design

  • Never aborts mid-run — a partial bundle beats no bundle. Every collector runs through a run_step wrapper and records OK / SKIP / FAIL / DENIED into collection-summary.txt inside the bundle. Only temp-dir/archive failures are fatal.
  • Capability probe before collection: API-server reachability (10s timeout, so a dead control plane can't stall the run), edge-host/agent-mode detection, distro detection, and an ordered non-fatal kubeconfig resolver (-k flag → $KUBECONFIG/run/kubeconfigadmin.conf$HOME$SUDO_USER home → rke2/k3s/canonical paths).
  • Flags: union of both legacy flag sets, plus -k <kubeconfig>, -K (host-only), -H (cluster-only), -q (quiet), -v (version).
  • Bundle naming and archive locations are unchanged from the legacy scripts: host-scope runs produce <hostname>-<ts>.tar.gz in the mktemp base dir (edge behavior — never writes to CWD, since edge hosts often have read-only partitions; -d relocates the base); cluster-only -H runs produce <cluster-name>-<ts>.tar.gz in -d/CWD (infra behavior).

⚠️ Behavioral changes vs. the legacy scripts

  1. RBAC gate is now advisory (was exit 1 in both scripts): denied namespaces/resources are pruned, recorded as DENIED with remediation guidance in namespace-coverage.txt, and collection continues.
  2. Missing/unset KUBECONFIG no longer aborts (infra exited 1): Kubernetes collection is recorded as SKIP and the host bundle is still produced.
  3. Root is required only when host collection is in scope; -H runs rootless, matching the infra script's historical behavior.

Bugs fixed in passing

  • Unquoted ${DISTRO} test; $TMPDIR//crictl paths when DISTRO unset (now ${DISTRO:-runtime})
  • var-log-pods glob errors when nothing matches (now compgen-guarded)
  • O(n²) sparse-array namespace pruning replaced with a single-listing rebuild
  • rke2 branch now collects var-log-pods (kubeadm/k3s/canonical already did)
  • cleanup() can no longer delete the tarball it just produced
  • LOGNAME sanitized against shell-hostile hostnames ($TMPDIR is used unquoted throughout the ported collectors)
  • PCG detection unified: matches either spectro-cloud-driver or jet in jet-system, guarded by the enterprise check

Docs

  • New README-support-bundle.md (flags, kubeconfig resolution, summary statuses, RBAC behavior, per-scope output naming/locations, differences from legacy scripts)
  • README.md indexes the new script

Testing

  • bash -n and shellcheck --severity=error clean
  • Smoke-tested end to end (host-only -K, cluster-only -H, -K -H rejection, root gate with/without DEV): summary table, per-scope tarball destination/naming, and cleanup all verified
  • Not yet run on the real matrix — kubeadm edge host, agent-mode, k3s, rke2, Canonical snap, PCG, Enterprise/VerteX (TLS mongo), restricted-RBAC service account. Recommend field validation before publishing to software.spectrocloud.com.

Notes / open items

  • SB_VERSION is 20260817+dev; the publish workflow should stamp <UTC date>+<git sha> (D5) — both published legacy scripts currently share a stale version string despite differing content.
  • set -euo pipefail deliberately omitted (as in both legacy scripts): it contradicts the never-abort collection design.

🤖 Generated with Claude Code

Consolidate support-bundle-edge.sh (host + cluster) and
support-bundle-infra.sh (cluster-only) into a single capability-driven
script, per CONSOLIDATION-DESIGN.md. The legacy scripts are kept intact
as fallbacks until the consolidated script is widely adopted.

Highlights:
- Never aborts mid-run: every collector runs through run_step and
  records OK / SKIP / FAIL / DENIED into collection-summary.txt inside
  the bundle; the only fatal errors are temp-dir/archive failures.
- Advisory RBAC coverage: denied namespaces/resources are pruned and
  recorded with remediation guidance (namespace-coverage.txt) instead
  of exiting 1.
- Capability probe: API-server reachability (10s timeout), edge-host
  and agent-mode detection, distro detection, and an ordered non-fatal
  kubeconfig resolver (flag, env, /run/kubeconfig, admin.conf, HOME,
  SUDO_USER home, rke2/k3s/canonical paths).
- New flags on top of the union of both legacy flag sets:
  -k kubeconfig, -K host-only, -H cluster-only (no root required),
  -q quiet, -v version.
- Archive to CWD by default (-d overrides), bundle named
  <cluster>-<hostname>-<ts> degrading to <hostname>-<ts>; cluster name
  applied at tar time so the console.log tee pipe is never broken.
- Fixes ported in passing: quoted DISTRO checks, ${DISTRO:-runtime}
  output paths, compgen-guarded pod-log globs, O(n^2) namespace pruning
  replaced with single-listing rebuild, rke2 now collects var-log-pods,
  cleanup can no longer delete the tarball it just produced, LOGNAME
  sanitized against shell-hostile hostnames.

Docs: README-support-bundle.md added; README.md indexes the new script.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@brathina-spectro
brathina-spectro requested a review from a team as a code owner August 17, 2026 22:50
@brathina-spectro brathina-spectro changed the title feat(support-bundle): add consolidated support-bundle.sh collector WIP : feat(support-bundle): add consolidated support-bundle.sh collector Aug 17, 2026
@brathina-spectro
brathina-spectro requested a lite review from Copilot August 17, 2026 22:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new consolidated, capability-driven support-bundle.sh that unifies the legacy edge (host+cluster) and infra (cluster-only) support bundle collectors, along with documentation updates to introduce and explain the new flow.

Changes:

  • Introduces support-bundle.sh with capability probes, non-fatal step execution, collection summaries, and unified flag set.
  • Updates support-bundle docs to reference and document the consolidated script (flags, kubeconfig resolution, RBAC behavior, output format).
  • Keeps legacy scripts available as documented fallbacks while the consolidated script is adopted.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
support-bundle/support-bundle.sh New consolidated collector script spanning host + Kubernetes collection with capability gating and summary output.
support-bundle/README.md Adds an index section for the consolidated script and links to the new documentation.
support-bundle/README-support-bundle.md New consolidated-script documentation (flags, kubeconfig resolution, RBAC behavior, output).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +140 to +142
function setup() {
TMPDIR_BASE=$(mktemp -d $MKTEMP_BASEDIR) || { techo 'Creating temporary directory failed, please check options'; exit 1; }
techo "Created temporary directory: $TMPDIR_BASE"
Comment on lines +282 to +284
[ -n "$KUBECONFIG_FLAG" ] && CANDIDATES+=("$KUBECONFIG_FLAG")
[ -n "$KUBECONFIG" ] && CANDIDATES+=("$KUBECONFIG")
CANDIDATES+=("$DEFAULT_KUBECONFIG" "/etc/kubernetes/admin.conf" "$HOME/.kube/config")
Comment on lines +455 to +459
function networking-info() {
techo "Collecting network info"
mkdir -p $TMPDIR/networking
iptables-save > $TMPDIR/networking/iptablessave 2>&1
ip6tables-save > $TMPDIR/networking/ip6tablessave 2>&1
Comment on lines +518 to +522
for logfile in /var/log/*log*; do
if file "$logfile" | grep -q "text"; then
cp -p "$logfile" "$TMPDIR/var/log" 2>&1
fi
done
Comment on lines +1521 to +1523
fi
MONGO_AUTH="-u root -p $DB_PASSWORD --authenticationDatabase admin"
fi
* **Kubernetes tier** (skipped with `-K`): cluster info and dump, cluster- and namespace-scoped resources, custom resources, helm release secrets, metrics, previous pod logs, and — on Enterprise/PCG clusters — MongoDB replica set status, per-pod disk usage, and database/collection sizes.
* **Distro tier** (host + detected distribution): kubeadm manifests/certs/etcd, k3s/rke2 pod logs and certs, Canonical snap k8s files/dqlite state.

Secrets are not collected, except helm release secrets for the spectro namespaces. Certificates are captured parsed (`openssl x509 -text -noout`), never as raw keys.
Review feedback on #40: edge hosts often have read-only partitions, so
the archive must never default to the current working directory, and
bundle names should stay recognizable per scope.

- Host-scope runs archive into the mktemp base dir and are named
  <hostname>-<ts>, exactly as support-bundle-edge.sh did (-d still
  relocates the base).
- Cluster-only (-H) runs archive to -d, else CWD, and are named
  <cluster-name>-<ts>, exactly as support-bundle-infra.sh did.
- Drop the combined <cluster>-<hostname>-<ts> naming scheme.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants