This commit consolidates the first production-ready baseline for krust, including core runtime behavior, operator UX, safety rails, and project publication assets.\n\nCore runtime and architecture\n- Implement lazy, active-scope watch-plan reconciliation across contexts/kinds/namespaces\n- Keep warm-context retention bounded by TTL for faster context switching\n- Add bounded watch reconnect handling and terminal handling for RBAC-forbidden watchers\n- Keep invalidation-driven rendering with FPS control and bounded log/state paths\n\nOperator UX and workflows\n- Expand k9s-style navigation/command aliases for supported Kubernetes resources\n- Improve pane consistency for table/detail/log overlays and scrolling behavior\n- Add detail viewer search semantics (non-destructive search/highlight) with match navigation\n- Add YAML/JSON detail format toggle and syntax highlighting for both formats\n- Add secret decode pane improvements and format-aware edit/apply behavior\n- Add clipboard copy and dump flows with native backend + OSC52 fallback\n\nSafety and action model\n- Keep readonly enforcement for mutation paths\n- Maintain guarded action behavior and clearer error/status surfacing\n\nDocumentation and open-source readiness\n- Rewrite README for community-facing onboarding and operational clarity\n- Add architecture and performance guides under docs/\n- Add CONTRIBUTING guide and PR template\n- Add GitHub Actions CI pipeline (fmt/check/test/release build)\n- Add GitHub Actions release pipeline for tagged multi-platform artifacts\n- Add Cargo package metadata and repository links\n- Add .gitignore hygiene for macOS Finder artifacts\n\nQuality and verification\n- Bring strict clippy (-D warnings) to clean state for current codebase\n- Validate full required pipeline: fmt, check, test, and release build
147 lines
3.9 KiB
Markdown
147 lines
3.9 KiB
Markdown
# krust Architecture
|
|
|
|
This document describes the current architecture and the design constraints behind it.
|
|
|
|
## Design Intent
|
|
|
|
`krust` is optimized for operators running large fleets:
|
|
|
|
- many kubeconfig contexts
|
|
- large object counts per context
|
|
- frequent state churn
|
|
|
|
The architecture is built to keep interaction latency stable under those conditions.
|
|
|
|
## Layered Model
|
|
|
|
`krust` is structured as four layers:
|
|
|
|
1. Cluster IO
|
|
2. State cache
|
|
3. View projection
|
|
4. TUI renderer
|
|
|
|
## 1) Cluster IO (`ResourceProvider`, `ActionExecutor`)
|
|
|
|
Primary responsibilities:
|
|
|
|
- initialize per-context Kubernetes clients lazily
|
|
- manage dynamic watch plans (`replace_watch_plan`)
|
|
- stream pod logs
|
|
- execute guarded mutation actions
|
|
|
|
Notable behavior:
|
|
|
|
- watchers are not started for every context/resource at startup
|
|
- watch plans are reconciled to active UI scope
|
|
- RBAC `403` watcher failures are treated as terminal for that resource/context
|
|
- exponential watch reconnect backoff is bounded and resets after healthy runs
|
|
|
|
## 2) State Cache (`StateStore`)
|
|
|
|
The cache stores normalized entities keyed by `(context, kind, namespace, name)` and keeps supporting indexes:
|
|
|
|
- context/kind index for fast listing
|
|
- namespace index by context
|
|
- context-scoped error state
|
|
- monotonic revision counter
|
|
|
|
The cache receives `StateDelta` messages (`Upsert`, `Remove`, `Reset`, `Error`) and applies them atomically.
|
|
|
|
## 3) View Projection (`ViewProjector`)
|
|
|
|
Projection transforms state cache data into active-view rows and detail content.
|
|
|
|
Key properties:
|
|
|
|
- projection is scoped to current `ViewRequest` (`context`, `kind`, `namespace`, `filter`, sort)
|
|
- cached projection is reused while request + state revision are unchanged
|
|
- avoids whole-state recompute on every keypress when inputs are stable
|
|
|
|
## 4) TUI Renderer (`ratatui` + `crossterm`)
|
|
|
|
Render strategy:
|
|
|
|
- invalidation-driven draws
|
|
- frame cap (`fps_limit`)
|
|
- coalesced state/input events
|
|
- bounded scroll behavior for table/detail/log panes
|
|
|
|
The UI can render table, describe, decode, events, and logs panes, plus selection overlays.
|
|
|
|
## Watch Scope Reconciliation
|
|
|
|
`replace_watch_plan(context, targets)` is the key boundary between UI intent and API load.
|
|
|
|
Inputs:
|
|
|
|
- active context
|
|
- active kind/pane requirements
|
|
- namespace scope
|
|
- warm-context retention policy
|
|
|
|
Outputs:
|
|
|
|
- start only missing required watchers
|
|
- stop watchers no longer needed
|
|
- retain watchers only for active and warm contexts
|
|
|
|
This prevents default "watch everything" fan-out.
|
|
|
|
## Warm Context Strategy
|
|
|
|
To make tab switches fast without broad eager loading:
|
|
|
|
- last-active contexts are tracked
|
|
- up to `warm_contexts` inactive contexts are retained
|
|
- retention expires after `warm_context_ttl_secs`
|
|
|
|
## Logs Pipeline
|
|
|
|
Logs are streamed per selected scope using pod log streams.
|
|
|
|
Current behavior supports:
|
|
|
|
- pod-level logs (all containers or selected container)
|
|
- deployment/replicaset fan-out to replica pod streams
|
|
- pause/resume, tail mode, latest jump
|
|
- source-level visibility filtering
|
|
|
|
For stability:
|
|
|
|
- bounded event drain per UI cycle
|
|
- bounded in-memory log buffer
|
|
- reconnect backoff for retryable stream failures
|
|
|
|
## Detail Content and Editing
|
|
|
|
Describe/decode/event detail views support:
|
|
|
|
- YAML/JSON render format toggle
|
|
- syntax highlighting + search highlighting
|
|
- external editor mutation flow
|
|
|
|
Mutation semantics:
|
|
|
|
- describe edit applies raw manifest as entered
|
|
- secret decode edit expects decoded values, then re-encodes to `Secret.data`
|
|
|
|
## Error Model
|
|
|
|
Error handling is explicit and user-visible:
|
|
|
|
- watcher errors are emitted as `StateDelta::Error`
|
|
- RBAC/action failures are surfaced in status line with context
|
|
- read-only mode blocks mutation actions early
|
|
|
|
## Internal Stable Interfaces
|
|
|
|
The code is intentionally organized around interface seams:
|
|
|
|
- `ResourceProvider`
|
|
- `ActionExecutor`
|
|
- `ViewProjector`
|
|
- `StateDelta`
|
|
|
|
These boundaries make it possible to evolve behavior while preserving operational semantics.
|