feat: establish krust v0.1 foundation with k9s-compatible UX and OSS release scaffolding
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
This commit is contained in:
1 parent
44d9b3e3ac
commit
ffa8a7cb50
20 files changed
+2632
-294
No files matched your search
@@ -0,0 +1,25 @@
|
||||
## Summary
|
||||
|
||||
Describe what changed and why.
|
||||
|
||||
## Validation
|
||||
|
||||
- [ ] cargo fmt --all
|
||||
- [ ] cargo check
|
||||
- [ ] cargo test
|
||||
- [ ] cargo build --release
|
||||
|
||||
## Performance Impact
|
||||
|
||||
If this touches watches/projection/render/logs, include impact notes.
|
||||
|
||||
- Hot path changed:
|
||||
- CPU/memory impact:
|
||||
- API pressure impact:
|
||||
- Failure-mode impact (RBAC/auth/network):
|
||||
|
||||
## Compatibility and UX
|
||||
|
||||
- [ ] keybinding behavior reviewed (k9s compatibility where applicable)
|
||||
- [ ] command behavior reviewed
|
||||
- [ ] docs updated for user-visible changes
|
||||
@@ -0,0 +1,42 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
name: Validate (fmt/check/test/build)
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Cache Rust artifacts
|
||||
uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: cargo fmt --all -- --check
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
- name: cargo check --locked
|
||||
run: cargo check --locked
|
||||
|
||||
- name: cargo test --locked
|
||||
run: cargo test --locked
|
||||
|
||||
- name: cargo build --release --locked
|
||||
run: cargo build --release --locked
|
||||
@@ -0,0 +1,81 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
concurrency:
|
||||
group: release-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build ${{ matrix.target }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-unknown-linux-gnu
|
||||
- os: macos-13
|
||||
target: x86_64-apple-darwin
|
||||
- os: macos-14
|
||||
target: aarch64-apple-darwin
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Add target
|
||||
run: rustup target add ${{ matrix.target }}
|
||||
|
||||
- name: Cache Rust artifacts
|
||||
uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Build release binary
|
||||
run: cargo build --release --locked --target ${{ matrix.target }}
|
||||
|
||||
- name: Package artifact
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TARGET='${{ matrix.target }}'
|
||||
PKG="krust-${TARGET}"
|
||||
mkdir -p "dist/${PKG}"
|
||||
cp "target/${TARGET}/release/krust" "dist/${PKG}/krust"
|
||||
cp README.md LICENSE "dist/${PKG}/"
|
||||
tar -C dist -czf "dist/${PKG}.tar.gz" "${PKG}"
|
||||
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: package-${{ matrix.target }}
|
||||
path: dist/krust-${{ matrix.target }}.tar.gz
|
||||
if-no-files-found: error
|
||||
|
||||
publish:
|
||||
name: Publish GitHub Release
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Download packaged artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: package-*
|
||||
path: dist
|
||||
merge-multiple: true
|
||||
|
||||
- name: Create release and upload artifacts
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: dist/*.tar.gz
|
||||
generate_release_notes: true
|
||||
@@ -24,3 +24,7 @@ target
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
||||
# macOS Finder artifacts
|
||||
.DS_Store
|
||||
**/.DS_Store
|
||||
@@ -1,7 +1,7 @@
|
||||
# AGENTS.md
|
||||
|
||||
## Project Intent
|
||||
`krs` is a latency-first, power-user Kubernetes TUI for very large environments:
|
||||
`krust` is a latency-first, power-user Kubernetes TUI for very large environments:
|
||||
- many contexts/clusters
|
||||
- many resources per cluster
|
||||
- frequent churn
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
# Contributing to krust
|
||||
|
||||
Thanks for contributing to `krust`.
|
||||
|
||||
This project is built for operators running large Kubernetes estates, so performance and operational clarity are non-negotiable.
|
||||
|
||||
## Principles
|
||||
|
||||
When proposing changes, optimize for these outcomes:
|
||||
|
||||
- low input-to-render latency under churn
|
||||
- controlled Kubernetes API pressure
|
||||
- bounded memory growth
|
||||
- predictable, keyboard-first UX
|
||||
- clear behavior under RBAC/auth/network failures
|
||||
|
||||
If a feature conflicts with these principles, prefer the simpler and faster path.
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Rust stable toolchain
|
||||
- kubeconfig with at least one working context
|
||||
- macOS or Linux environment
|
||||
|
||||
### Clone and build
|
||||
|
||||
```bash
|
||||
git clone git@github.com:ErfanY/krust.git
|
||||
cd krust
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
Run locally:
|
||||
|
||||
```bash
|
||||
cargo run -- --context <context-name>
|
||||
```
|
||||
|
||||
## Required Validation Pipeline
|
||||
|
||||
Run this sequence before opening or updating a PR:
|
||||
|
||||
```bash
|
||||
cargo fmt --all
|
||||
cargo check
|
||||
cargo test
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
The CI pipeline enforces the same flow.
|
||||
|
||||
## Code and Design Expectations
|
||||
|
||||
## Performance-sensitive changes
|
||||
|
||||
If your change touches watchers, projection, rendering, or logs, include in your PR description:
|
||||
|
||||
- what hot path changed
|
||||
- expected complexity/cost impact
|
||||
- API watch/list pressure impact
|
||||
- memory impact and bounds
|
||||
- failure-mode behavior (RBAC/auth/disconnect)
|
||||
|
||||
Use [`docs/performance.md`](docs/performance.md) as the baseline.
|
||||
|
||||
## API/watch behavior
|
||||
|
||||
- avoid eager all-context/all-kind watchers by default
|
||||
- prefer active-scope/lazy activation
|
||||
- keep reconnect logic bounded
|
||||
- treat RBAC denials as expected operational state
|
||||
|
||||
## UX behavior
|
||||
|
||||
- preserve existing keybindings unless explicitly changing compatibility behavior
|
||||
- avoid introducing mode ambiguities
|
||||
- keep detail/log scrolling and search behavior predictable
|
||||
|
||||
## Testing Guidance
|
||||
|
||||
Add or update tests when changing behavior:
|
||||
|
||||
- unit tests for parsing, formatting, and helper logic
|
||||
- state/projection tests when list or sorting behavior changes
|
||||
- UI behavior tests for keybinding and pane semantics
|
||||
|
||||
Performance benchmark tests can be added as ignored tests.
|
||||
|
||||
## Pull Request Checklist
|
||||
|
||||
Before requesting review, verify:
|
||||
|
||||
- [ ] `cargo fmt --all`
|
||||
- [ ] `cargo check`
|
||||
- [ ] `cargo test`
|
||||
- [ ] `cargo build --release`
|
||||
- [ ] docs updated (`README`/`docs/*`) for user-visible changes
|
||||
- [ ] performance notes included for hot-path changes
|
||||
|
||||
## Commit Style
|
||||
|
||||
Use imperative commit titles and keep scope tight.
|
||||
|
||||
Good examples:
|
||||
|
||||
- `ui: clamp detail scroll bounds for wrapped views`
|
||||
- `cluster: disable forbidden watchers per context/kind`
|
||||
- `docs: add performance tuning guide`
|
||||
|
||||
## Security and Sensitive Data
|
||||
|
||||
- never commit kubeconfigs, tokens, certificates, or customer data
|
||||
- redact cluster/account identifiers from logs/screenshots in PRs where possible
|
||||
- for sensitive reports, contact maintainers privately
|
||||
|
||||
## Need help?
|
||||
|
||||
Open an issue with:
|
||||
|
||||
- expected behavior
|
||||
- current behavior
|
||||
- reproducible steps
|
||||
- environment (`krust` version, OS, Kubernetes version)
|
||||
Generated
+2
-1
@@ -1042,7 +1042,7 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "krs"
|
||||
name = "krust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
@@ -1059,6 +1059,7 @@ dependencies = [
|
||||
"ratatui",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
"thiserror 2.0.18",
|
||||
"tokio",
|
||||
"toml",
|
||||
|
||||
+7
-1
@@ -1,7 +1,12 @@
|
||||
[package]
|
||||
name = "krs"
|
||||
name = "krust"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
description = "Latency-first Kubernetes terminal navigator for multi-cluster operators"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/ErfanY/krust"
|
||||
homepage = "https://github.com/ErfanY/krust"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.102"
|
||||
@@ -17,6 +22,7 @@ kube-runtime = "3.0.1"
|
||||
ratatui = { version = "0.30.0", default-features = false, features = ["crossterm"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.149"
|
||||
serde_yaml = "0.9.34"
|
||||
thiserror = "2.0.18"
|
||||
tokio = { version = "1.50.0", features = ["macros", "rt-multi-thread", "signal", "sync", "time"] }
|
||||
toml = "1.0.6"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Erfan Yousefi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,44 +1,136 @@
|
||||
# krs
|
||||
# krust
|
||||
|
||||
High-performance Kubernetes terminal navigator in Rust.
|
||||
[](https://github.com/ErfanY/krust/actions/workflows/ci.yml)
|
||||
[](https://github.com/ErfanY/krust/actions/workflows/release.yml)
|
||||
[](LICENSE)
|
||||
[](https://kubernetes.io/)
|
||||
|
||||
Built against `k8s-openapi` `v1_33` (targeting Kubernetes `1.33+` clusters).
|
||||
`krust` is a latency-first Kubernetes terminal navigator for operators who work across many clusters and large resource sets.
|
||||
|
||||
## Current Status
|
||||
It is intentionally focused on fast core workflows (navigation, inspect, logs, safe edits/actions) with high k9s shortcut compatibility, while keeping API pressure and UI jitter under control.
|
||||
|
||||
`krs` now includes a working foundation for the plan:
|
||||
Built with Rust (`tokio`, `kube`, `kube_runtime`, `ratatui`) and compiled against Kubernetes `1.33+` APIs (`k8s-openapi` `v1_33`).
|
||||
|
||||
- Layered architecture: `cluster IO` -> `state cache` -> `view projector` -> `TUI renderer`
|
||||
- Multi-context tabs in one session
|
||||
- Lazy watch activation with active-context watch plans (inactive context watchers are paused)
|
||||
- Event-driven state deltas over bounded channels
|
||||
- Invalidation-based rendering with FPS cap
|
||||
- Kubernetes watch streams for a broad set of core resource kinds
|
||||
- k9s-style keyboard navigation, filter/sort, table + describe/events/logs panes
|
||||
- Safe mutation workflow with confirmation (`delete` implemented for Pods)
|
||||
- `config.toml` and `keymap.toml` loading
|
||||
## Why krust
|
||||
|
||||
## CLI
|
||||
Most terminal Kubernetes tools become noisy or sluggish when context count and watch volume grow. `krust` is designed around a different default:
|
||||
|
||||
- activate only the watch scope needed for what you are currently looking at
|
||||
- keep render work invalidation-driven with a frame cap
|
||||
- keep logs bounded and stream-focused
|
||||
- treat RBAC denials and API turbulence as normal operational states
|
||||
|
||||
This is also why plugins are out of scope for v1: predictable latency and operational clarity come first.
|
||||
|
||||
## Scope and Non-Goals
|
||||
|
||||
What `krust` is:
|
||||
|
||||
- keyboard-first multi-context Kubernetes navigator
|
||||
- read-heavy operations with guarded mutations
|
||||
- high-signal terminal UI for SRE/platform workflows
|
||||
|
||||
What `krust` is not:
|
||||
|
||||
- a plugin/script execution platform
|
||||
- a replacement for full GitOps pipelines or IDE workflows
|
||||
- a "watch everything everywhere" cluster crawler at startup
|
||||
|
||||
## Feature Matrix
|
||||
|
||||
| Area | Status | Notes |
|
||||
| --- | --- | --- |
|
||||
| Multi-context session | Implemented | Context tabs with fast switching and warm-context retention |
|
||||
| Namespace scoping | Implemented | Namespace picker and `all` namespace mode |
|
||||
| Core resource browser | Implemented | Pods, Deployments, RS, STS, DS, Services, Ingresses, ConfigMaps, Secrets, Jobs, CronJobs, PVC/PV, Nodes, Namespaces, Events, SA, Roles, RB/CR/CRB, NetPol, HPA, PDB |
|
||||
| Describe pane | Implemented | YAML/JSON view toggle with syntax highlighting |
|
||||
| Secret decode pane | Implemented | Decoded view + edit/apply with automatic base64 re-encode |
|
||||
| Logs pane | Implemented | Streaming with pause/tail/source filtering; pod multi-container and deploy/rs replica fan-out |
|
||||
| Edit/apply | Implemented | External editor flow from describe/decode panes |
|
||||
| Delete action | Implemented | Guarded delete path (currently Pods) |
|
||||
| k9s-style commands/aliases | Partial parity | Core resource commands and navigation implemented; plugin commands intentionally out of scope |
|
||||
| Plugin subsystem | Out of scope | Deliberately excluded for performance and simplicity |
|
||||
|
||||
## Compatibility
|
||||
|
||||
- OS: macOS, Linux
|
||||
- Kubernetes: `1.33+`
|
||||
- Auth: standard kubeconfig + exec auth providers
|
||||
- Terminal: basic color through truecolor; OSC52 clipboard fallback supported
|
||||
|
||||
## Installation and Quick Start
|
||||
|
||||
### Install from GitHub Releases (recommended)
|
||||
|
||||
Prebuilt archives are published for:
|
||||
|
||||
- `x86_64-unknown-linux-gnu`
|
||||
- `x86_64-apple-darwin`
|
||||
- `aarch64-apple-darwin`
|
||||
|
||||
Example (Linux x86_64):
|
||||
|
||||
```bash
|
||||
krs
|
||||
krs --context dev-cluster
|
||||
krs --namespace payments
|
||||
krs --readonly
|
||||
krs --kubeconfig ~/.kube/config
|
||||
krs --all-contexts # optional eager auth/client warmup across contexts
|
||||
curl -L -o krust.tar.gz \
|
||||
https://github.com/ErfanY/krust/releases/latest/download/krust-x86_64-unknown-linux-gnu.tar.gz
|
||||
|
||||
tar -xzf krust.tar.gz
|
||||
sudo install krust-x86_64-unknown-linux-gnu/krust /usr/local/bin/krust
|
||||
```
|
||||
|
||||
## Config
|
||||
### Install from source
|
||||
|
||||
`~/.config/krs/config.toml`
|
||||
```bash
|
||||
cargo install --git https://github.com/ErfanY/krust.git --locked krust
|
||||
```
|
||||
|
||||
### Build locally
|
||||
|
||||
```bash
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
Binary path:
|
||||
|
||||
```bash
|
||||
target/release/krust
|
||||
```
|
||||
|
||||
### Run
|
||||
|
||||
```bash
|
||||
krust
|
||||
krust --context <context-name>
|
||||
krust --namespace <namespace>
|
||||
krust --readonly
|
||||
krust --kubeconfig <path>
|
||||
krust --all-contexts
|
||||
```
|
||||
|
||||
### CLI flags
|
||||
|
||||
- `--context`: initial context
|
||||
- `--namespace`: initial namespace scope
|
||||
- `--readonly`: disable mutations
|
||||
- `--kubeconfig`: explicit kubeconfig path
|
||||
- `--all-contexts`: eager auth/client warmup across all contexts
|
||||
|
||||
## Configuration
|
||||
|
||||
Runtime/UI config path:
|
||||
|
||||
- `~/.config/krust/config.toml`
|
||||
|
||||
Keymap override path:
|
||||
|
||||
- `~/.config/krust/keymap.toml`
|
||||
|
||||
Example `config.toml`:
|
||||
|
||||
```toml
|
||||
[runtime]
|
||||
fps_limit = 60
|
||||
delta_channel_capacity = 2048
|
||||
namespace = "default"
|
||||
default_context = "dev-cluster"
|
||||
warm_contexts = 1
|
||||
warm_context_ttl_secs = 20
|
||||
|
||||
@@ -47,94 +139,116 @@ theme = "default"
|
||||
show_help = true
|
||||
```
|
||||
|
||||
## Keymap
|
||||
Defaults for initial context/namespace come from kubeconfig unless CLI flags override them.
|
||||
|
||||
`~/.config/krs/keymap.toml`
|
||||
## Quick UX Reference
|
||||
|
||||
```toml
|
||||
quit = "ctrl+c"
|
||||
next_context = "tab"
|
||||
prev_context = "shift+tab"
|
||||
next_kind = "alt+right"
|
||||
prev_kind = "alt+left"
|
||||
move_down = "j"
|
||||
move_up = "k"
|
||||
goto_top = "g"
|
||||
goto_bottom = "shift+g"
|
||||
filter_mode = "/"
|
||||
cycle_sort = "s"
|
||||
toggle_desc = "r"
|
||||
cycle_namespace = "n"
|
||||
toggle_help = "?"
|
||||
to_table = "t"
|
||||
toggle_describe = "d"
|
||||
to_events = "shift+e"
|
||||
to_logs = "l"
|
||||
delete = "ctrl+d"
|
||||
confirm = "y"
|
||||
cancel = "esc"
|
||||
```
|
||||
|
||||
## Default Navigation
|
||||
### Core navigation
|
||||
|
||||
- `tab` / `shift+tab`: switch context tabs
|
||||
- `j` / `k` (or arrows): move selection, or scroll when viewing boxed text panes
|
||||
- `Enter`: on `Namespaces` selects namespace and returns to previous resource kind (fallback `Pods`); on resource tables opens describe
|
||||
- `w` in content box: toggle wrap on/off
|
||||
- when wrap is off: use left/right arrows for horizontal scroll
|
||||
- `/`: open command field in filter mode (type pattern and press `Enter`)
|
||||
- filter mode is realtime while typing; `Esc` cancels and restores previous filter
|
||||
- `:`: open command field in command mode
|
||||
- `tab` in command mode: autocomplete commands (and `:ctx` / `:kind` arguments)
|
||||
- `[` / `]`: command history back/forward
|
||||
- `-`: rerun previous command
|
||||
- `ctrl+a`: open resource alias list
|
||||
- `d`: toggle describe pane
|
||||
- `v`: k9s-style view (opens detail view)
|
||||
- `ctrl+d`: delete selected resource (with confirmation)
|
||||
- `ctrl+k`: k9s-style kill shortcut (mapped to guarded delete flow)
|
||||
- `esc`: close command/overlay and return focus
|
||||
- mouse wheel: scrolls inside overlay/detail/table box (terminal scrollback is not used)
|
||||
- top panes include live pod/cluster utilization from Pod requests/limits and Node allocatable
|
||||
- `j` / `k` (or arrows): move in tables, scroll in detail panes
|
||||
- `Enter`: select namespace in namespace view, otherwise open describe
|
||||
- `d`: describe
|
||||
- `ctrl+d`: delete (guarded)
|
||||
- `x`: secret decode view toggle
|
||||
- `l`: logs pane
|
||||
- `s`: log tail toggle
|
||||
- `p`: pause/resume logs
|
||||
- `S`: log source selector
|
||||
- `c`: container selector
|
||||
|
||||
## Command Field
|
||||
### Search and command bar
|
||||
|
||||
Examples in the command field:
|
||||
- `/`: filter in table/overlay panes, search in detail/log panes
|
||||
- `?`: detail/search shortcut
|
||||
- `n` / `N`: next/previous search match in detail/log panes
|
||||
- `:`: command mode (`:ctx`, `:ns`, `:po`, `:kind`, `:edit`, `:fmt`, etc.)
|
||||
- `tab` in command mode: autocomplete
|
||||
- `ctrl+w` in command/filter mode: delete previous word
|
||||
|
||||
- `:ctx` show contexts list in a selectable box (`j/k`, arrows, mouse wheel, `/` filter, `Enter` to switch)
|
||||
- `:ctx <context-name>` switch active context
|
||||
- `:ns [namespace|all]` with arg sets namespace scope, without arg opens Namespaces
|
||||
- `:all` (or `:0`) switch to all namespaces
|
||||
- `:kind <po|deploy|svc|...>` switch resource kind
|
||||
- `:po`, `:svc`, `:deploy`, `:ns`, ... k9s-style direct resource switches
|
||||
- `:resources` show shorthand resource aliases
|
||||
- `:clear` clear current filter
|
||||
- `:po kube-system`, `:po /api`, `:po @my-context`, `:deploy -l app=my-api` are supported
|
||||
- `:po --context <context> --namespace <ns>` and `:po -A` are supported
|
||||
- `/pod-xxx` apply table filter
|
||||
- `Tab` autocompletes command names and context/kind arguments
|
||||
### Detail viewing
|
||||
|
||||
## Watched Resource Kinds
|
||||
- `w`: wrap toggle
|
||||
- left/right: horizontal scroll (wrap off)
|
||||
- `gg` / `G`: top/bottom
|
||||
- `ctrl+u` / `ctrl+d`: half-page up/down
|
||||
- `y`: copy current view
|
||||
- `:dump <path>`: write current view to file
|
||||
|
||||
Pods, Deployments, ReplicaSets, StatefulSets, DaemonSets, Services, Ingresses, ConfigMaps,
|
||||
Secrets, Jobs, CronJobs, PVCs, PVs, Nodes, Namespaces, Events, ServiceAccounts, Roles,
|
||||
RoleBindings, ClusterRoles, ClusterRoleBindings, NetworkPolicies, HPAs, PDBs.
|
||||
### Format and edit
|
||||
|
||||
## Architecture Notes
|
||||
- `:fmt yaml|json` or `:yaml` / `:json`
|
||||
- `e` or `:edit [yaml|json]`
|
||||
|
||||
- `ResourceProvider` and `ActionExecutor` are stable internal interfaces.
|
||||
- `StateDelta` is the boundary from cluster runtime to UI state.
|
||||
- `ViewProjector` isolates table/detail projections from storage and rendering.
|
||||
- Watch loops reconnect with exponential backoff and emit contextual error deltas.
|
||||
- Context list is loaded from kubeconfig, but clients/watches are activated lazily on demand.
|
||||
- Watchers are reconciled to the active tab/pane scope (context + kind + namespace) to avoid fan-out.
|
||||
- One recently used context can be kept warm for fast tab switches (TTL-based).
|
||||
- `--all-contexts` enables eager client warmup across contexts.
|
||||
- `403 Forbidden` watchers are disabled per resource/context (no infinite retry flood).
|
||||
## Architecture Overview
|
||||
|
||||
## Next Milestones
|
||||
`krust` uses a layered architecture to isolate cluster IO, state mutation, projection, and rendering.
|
||||
|
||||
1. Add live pod logs streaming and resource-correlated event pane.
|
||||
2. Expand mutation actions (scale/restart/apply/edit/port-forward/exec) with RBAC-aware UX.
|
||||
3. Add integration tests against disposable clusters and load/perf benchmarks.
|
||||
4. Harden CRD discovery and generic resource browsing.
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A["Kubernetes API\n(list/watch/logs/actions)"] --> B["ResourceProvider\nwatch + stream + action adapters"]
|
||||
B --> C["StateDelta channel\n(bounded)"]
|
||||
C --> D["StateStore\nnormalized entities + indexes"]
|
||||
D --> E["ViewProjector\nactive-view projection"]
|
||||
E --> F["TUI Renderer\ninvalidated draws + FPS cap"]
|
||||
F --> G["Operator Input\nkeys, commands, filters"]
|
||||
G --> E
|
||||
G --> B
|
||||
```
|
||||
|
||||
Design details are documented in:
|
||||
|
||||
- [`docs/architecture.md`](docs/architecture.md)
|
||||
- [`docs/performance.md`](docs/performance.md)
|
||||
|
||||
## Performance Model (Operator-Facing)
|
||||
|
||||
`krust` prioritizes consistent interactivity over maximum background data ingestion.
|
||||
|
||||
- watch scope is reconciled to active context/pane needs
|
||||
- recently used contexts can stay warm with TTL
|
||||
- render loop is invalidation-driven with FPS cap
|
||||
- logs are ring-buffered with source filtering and bounded drain
|
||||
- forbidden RBAC watches are disabled for that context/resource (no retry floods)
|
||||
|
||||
For deeper technical details and tuning guidance, see [`docs/performance.md`](docs/performance.md).
|
||||
|
||||
## Safety Model
|
||||
|
||||
- `--readonly` blocks mutating actions
|
||||
- destructive action path is confirmation-guarded
|
||||
- RBAC/action failures are surfaced with explicit status messaging
|
||||
- secret decode editing converts decoded values back to base64 automatically
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### `403 Forbidden` warnings for some resources
|
||||
|
||||
This is usually expected RBAC scope mismatch. `krust` disables forbidden watchers for that resource/context to avoid reconnect storms.
|
||||
|
||||
### Long startup with many contexts
|
||||
|
||||
Default mode is lazy. If startup still feels heavy, avoid `--all-contexts` and keep `warm_contexts` low.
|
||||
|
||||
### Clipboard copy issues
|
||||
|
||||
`krust` uses platform-native commands first (`pbcopy` / `wl-copy` / `xclip` / `xsel`) and falls back to OSC52 where supported.
|
||||
|
||||
### Auth works in shell but not in app environment
|
||||
|
||||
Ensure your terminal session has the same kube auth env/credentials as your shell where `kubectl` succeeds.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contribution guide, PR standards, and performance review expectations live in [`CONTRIBUTING.md`](CONTRIBUTING.md).
|
||||
|
||||
## Roadmap (Near Term)
|
||||
|
||||
- wider mutation action set (scale/restart/etc.) with guardrails
|
||||
- richer event correlation for non-Event resources
|
||||
- expanded integration and load benchmarks
|
||||
- continued k9s command/keybinding compatibility tightening
|
||||
|
||||
## License
|
||||
|
||||
MIT. See [`LICENSE`](LICENSE).
|
||||
@@ -0,0 +1,146 @@
|
||||
# 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.
|
||||
@@ -0,0 +1,103 @@
|
||||
# krust Performance Guide
|
||||
|
||||
This document explains how `krust` keeps latency predictable and how to reason about performance-sensitive changes.
|
||||
|
||||
## Performance Priorities
|
||||
|
||||
In order:
|
||||
|
||||
1. Input responsiveness
|
||||
2. Controlled API pressure
|
||||
3. Bounded memory behavior
|
||||
4. Visual stability (no redraw thrash)
|
||||
|
||||
`krust` intentionally does not optimize for maximum background data breadth by default.
|
||||
|
||||
## Core Performance Mechanisms
|
||||
|
||||
### Lazy activation by default
|
||||
|
||||
- clients are initialized lazily per context
|
||||
- watchers are activated from the current watch plan
|
||||
- inactive contexts are not fully watched unless retained via warm-context policy
|
||||
|
||||
This avoids `contexts x resources x namespaces` startup explosion.
|
||||
|
||||
### Watch lifecycle controls
|
||||
|
||||
- dynamic watch-plan reconciliation (`replace_watch_plan`)
|
||||
- bounded exponential reconnect backoff
|
||||
- terminal handling for RBAC `403` watcher failures
|
||||
|
||||
Result: fewer reconnect storms and less API/server noise.
|
||||
|
||||
### Projection and render controls
|
||||
|
||||
- state cache revision tracking
|
||||
- cached projection reuse when request + revision unchanged
|
||||
- invalidation-based render loop with FPS cap
|
||||
|
||||
Result: no unconditional full redraw at fixed ticks.
|
||||
|
||||
### Log-path controls
|
||||
|
||||
- bounded line/byte buffer
|
||||
- bounded per-cycle drain
|
||||
- per-source filtering without restarting all streams
|
||||
- tail/pause behavior to reduce churn during operator inspection
|
||||
|
||||
Result: stable log UX under high stream volume.
|
||||
|
||||
## Configuration Knobs
|
||||
|
||||
`~/.config/krust/config.toml`
|
||||
|
||||
```toml
|
||||
[runtime]
|
||||
fps_limit = 60
|
||||
delta_channel_capacity = 2048
|
||||
warm_contexts = 1
|
||||
warm_context_ttl_secs = 20
|
||||
```
|
||||
|
||||
Tuning suggestions:
|
||||
|
||||
- many contexts: keep `warm_contexts` low (`0-2`)
|
||||
- bursty clusters: raise `delta_channel_capacity` carefully
|
||||
- low-power terminals: reduce `fps_limit` (for example `30`)
|
||||
|
||||
## Operational Recommendations
|
||||
|
||||
- default startup: use lazy mode (`krust`)
|
||||
- only use `--all-contexts` when eager auth/client warmup is explicitly desired
|
||||
- scope namespace when debugging dense clusters
|
||||
- in logs, pause or source-filter when hunting specific signals
|
||||
|
||||
## Benchmark and Validation Hooks
|
||||
|
||||
`krust` includes perf-focused test hooks (some ignored by default) and should always pass full validation:
|
||||
|
||||
```bash
|
||||
cargo fmt --all
|
||||
cargo check
|
||||
cargo test
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
You can run ignored perf tests explicitly when profiling local changes:
|
||||
|
||||
```bash
|
||||
cargo test -- --ignored --nocapture
|
||||
```
|
||||
|
||||
## Change Review Checklist (Perf-Sensitive PRs)
|
||||
|
||||
When changing watches, rendering, projection, or logs, include:
|
||||
|
||||
- hot path changed
|
||||
- expected complexity/cost change
|
||||
- API pressure impact
|
||||
- memory impact and bounds
|
||||
- potential regressions and how to observe them
|
||||
|
||||
This keeps performance discussion concrete and reviewable.
|
||||
+1
-1
@@ -4,7 +4,7 @@ use clap::Parser;
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[command(
|
||||
name = "krs",
|
||||
name = "krust",
|
||||
version,
|
||||
about = "High-performance Kubernetes terminal navigator"
|
||||
)]
|
||||
|
||||
@@ -26,8 +26,9 @@ use k8s_openapi::{
|
||||
};
|
||||
use kube::{
|
||||
Api, Client, Config, Resource, ResourceExt,
|
||||
api::{DeleteParams, LogParams},
|
||||
api::{DeleteParams, LogParams, PostParams},
|
||||
config::{KubeConfigOptions, Kubeconfig},
|
||||
core::{ApiResource, DynamicObject, GroupVersionKind},
|
||||
};
|
||||
use kube_runtime::watcher::{self, Event};
|
||||
use serde::Serialize;
|
||||
@@ -46,7 +47,6 @@ pub struct KubeProviderOptions {
|
||||
pub kubeconfig: Option<PathBuf>,
|
||||
pub context: Option<String>,
|
||||
pub all_contexts: bool,
|
||||
pub namespace: Option<String>,
|
||||
pub readonly: bool,
|
||||
pub warm_contexts: usize,
|
||||
pub warm_context_ttl_secs: u64,
|
||||
@@ -172,6 +172,15 @@ impl KubeResourceProvider {
|
||||
clients.insert(context.to_string(), client.clone());
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
pub fn default_namespace_for_context(&self, context: &str) -> Option<String> {
|
||||
self.kubeconfig
|
||||
.contexts
|
||||
.iter()
|
||||
.find(|named| named.name == context)
|
||||
.and_then(|named| named.context.as_ref())
|
||||
.and_then(|ctx| ctx.namespace.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -239,10 +248,8 @@ impl ResourceProvider for KubeResourceProvider {
|
||||
} else {
|
||||
warm_contexts.contains(&key.context)
|
||||
};
|
||||
if !keep_existing {
|
||||
if let Some(task) = watched.remove(&key) {
|
||||
task.abort();
|
||||
}
|
||||
if !keep_existing && let Some(task) = watched.remove(&key) {
|
||||
task.abort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,6 +374,228 @@ impl ActionExecutor for KubeResourceProvider {
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
async fn replace_resource(
|
||||
&self,
|
||||
key: &ResourceKey,
|
||||
manifest: serde_json::Value,
|
||||
) -> Result<ActionResult, ActionError> {
|
||||
if self.readonly {
|
||||
return Err(ActionError::ReadOnly);
|
||||
}
|
||||
|
||||
let client = self
|
||||
.client_for_context(&key.context)
|
||||
.await
|
||||
.map_err(|err| ActionError::Failed(err.to_string()))?;
|
||||
|
||||
let spec = api_resource_spec_for_kind(key.kind).ok_or_else(|| {
|
||||
ActionError::Unsupported(format!("replace {} is not implemented yet", key.kind))
|
||||
})?;
|
||||
let gvk = GroupVersionKind::gvk(spec.group, spec.version, spec.kind);
|
||||
let mut ar = ApiResource::from_gvk(&gvk);
|
||||
ar.plural = spec.plural.to_string();
|
||||
let obj: DynamicObject = serde_json::from_value(manifest)
|
||||
.map_err(|err| ActionError::Failed(format!("invalid manifest: {err}")))?;
|
||||
|
||||
if spec.namespaced {
|
||||
let namespace = key.namespace.as_deref().unwrap_or("default");
|
||||
let api: Api<DynamicObject> = Api::namespaced_with(client, namespace, &ar);
|
||||
api.replace(&key.name, &PostParams::default(), &obj)
|
||||
.await
|
||||
.map_err(map_kube_error)?;
|
||||
} else {
|
||||
let api: Api<DynamicObject> = Api::all_with(client, &ar);
|
||||
api.replace(&key.name, &PostParams::default(), &obj)
|
||||
.await
|
||||
.map_err(map_kube_error)?;
|
||||
}
|
||||
|
||||
Ok(ActionResult {
|
||||
message: format!("{} {} updated", key.kind.short_name(), key.name),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct ApiResourceSpec {
|
||||
group: &'static str,
|
||||
version: &'static str,
|
||||
kind: &'static str,
|
||||
plural: &'static str,
|
||||
namespaced: bool,
|
||||
}
|
||||
|
||||
fn api_resource_spec_for_kind(kind: ResourceKind) -> Option<ApiResourceSpec> {
|
||||
Some(match kind {
|
||||
ResourceKind::Pods => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "Pod",
|
||||
plural: "pods",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::Deployments => ApiResourceSpec {
|
||||
group: "apps",
|
||||
version: "v1",
|
||||
kind: "Deployment",
|
||||
plural: "deployments",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::ReplicaSets => ApiResourceSpec {
|
||||
group: "apps",
|
||||
version: "v1",
|
||||
kind: "ReplicaSet",
|
||||
plural: "replicasets",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::StatefulSets => ApiResourceSpec {
|
||||
group: "apps",
|
||||
version: "v1",
|
||||
kind: "StatefulSet",
|
||||
plural: "statefulsets",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::DaemonSets => ApiResourceSpec {
|
||||
group: "apps",
|
||||
version: "v1",
|
||||
kind: "DaemonSet",
|
||||
plural: "daemonsets",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::Services => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "Service",
|
||||
plural: "services",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::Ingresses => ApiResourceSpec {
|
||||
group: "networking.k8s.io",
|
||||
version: "v1",
|
||||
kind: "Ingress",
|
||||
plural: "ingresses",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::ConfigMaps => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "ConfigMap",
|
||||
plural: "configmaps",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::Secrets => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "Secret",
|
||||
plural: "secrets",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::Jobs => ApiResourceSpec {
|
||||
group: "batch",
|
||||
version: "v1",
|
||||
kind: "Job",
|
||||
plural: "jobs",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::CronJobs => ApiResourceSpec {
|
||||
group: "batch",
|
||||
version: "v1",
|
||||
kind: "CronJob",
|
||||
plural: "cronjobs",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::PersistentVolumeClaims => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "PersistentVolumeClaim",
|
||||
plural: "persistentvolumeclaims",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::PersistentVolumes => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "PersistentVolume",
|
||||
plural: "persistentvolumes",
|
||||
namespaced: false,
|
||||
},
|
||||
ResourceKind::Nodes => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "Node",
|
||||
plural: "nodes",
|
||||
namespaced: false,
|
||||
},
|
||||
ResourceKind::Namespaces => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "Namespace",
|
||||
plural: "namespaces",
|
||||
namespaced: false,
|
||||
},
|
||||
ResourceKind::Events => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "Event",
|
||||
plural: "events",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::ServiceAccounts => ApiResourceSpec {
|
||||
group: "",
|
||||
version: "v1",
|
||||
kind: "ServiceAccount",
|
||||
plural: "serviceaccounts",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::Roles => ApiResourceSpec {
|
||||
group: "rbac.authorization.k8s.io",
|
||||
version: "v1",
|
||||
kind: "Role",
|
||||
plural: "roles",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::RoleBindings => ApiResourceSpec {
|
||||
group: "rbac.authorization.k8s.io",
|
||||
version: "v1",
|
||||
kind: "RoleBinding",
|
||||
plural: "rolebindings",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::ClusterRoles => ApiResourceSpec {
|
||||
group: "rbac.authorization.k8s.io",
|
||||
version: "v1",
|
||||
kind: "ClusterRole",
|
||||
plural: "clusterroles",
|
||||
namespaced: false,
|
||||
},
|
||||
ResourceKind::ClusterRoleBindings => ApiResourceSpec {
|
||||
group: "rbac.authorization.k8s.io",
|
||||
version: "v1",
|
||||
kind: "ClusterRoleBinding",
|
||||
plural: "clusterrolebindings",
|
||||
namespaced: false,
|
||||
},
|
||||
ResourceKind::NetworkPolicies => ApiResourceSpec {
|
||||
group: "networking.k8s.io",
|
||||
version: "v1",
|
||||
kind: "NetworkPolicy",
|
||||
plural: "networkpolicies",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::HorizontalPodAutoscalers => ApiResourceSpec {
|
||||
group: "autoscaling",
|
||||
version: "v2",
|
||||
kind: "HorizontalPodAutoscaler",
|
||||
plural: "horizontalpodautoscalers",
|
||||
namespaced: true,
|
||||
},
|
||||
ResourceKind::PodDisruptionBudgets => ApiResourceSpec {
|
||||
group: "policy",
|
||||
version: "v1",
|
||||
kind: "PodDisruptionBudget",
|
||||
plural: "poddisruptionbudgets",
|
||||
namespaced: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn load_kubeconfig(path: Option<&PathBuf>) -> anyhow::Result<Kubeconfig> {
|
||||
|
||||
@@ -75,4 +75,9 @@ pub trait ResourceProvider: Send + Sync {
|
||||
#[async_trait]
|
||||
pub trait ActionExecutor: Send + Sync {
|
||||
async fn delete_resource(&self, key: &ResourceKey) -> Result<ActionResult, ActionError>;
|
||||
async fn replace_resource(
|
||||
&self,
|
||||
key: &ResourceKey,
|
||||
manifest: serde_json::Value,
|
||||
) -> Result<ActionResult, ActionError>;
|
||||
}
|
||||
+3
-16
@@ -3,22 +3,13 @@ use std::{fs, path::PathBuf};
|
||||
use anyhow::Context;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct AppConfig {
|
||||
pub runtime: RuntimeConfig,
|
||||
pub ui: UiConfig,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
runtime: RuntimeConfig::default(),
|
||||
ui: UiConfig::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn load() -> anyhow::Result<Self> {
|
||||
let path = default_config_path();
|
||||
@@ -39,8 +30,6 @@ impl AppConfig {
|
||||
pub struct RuntimeConfig {
|
||||
pub fps_limit: u16,
|
||||
pub delta_channel_capacity: usize,
|
||||
pub namespace: Option<String>,
|
||||
pub default_context: Option<String>,
|
||||
pub warm_contexts: usize,
|
||||
pub warm_context_ttl_secs: u64,
|
||||
}
|
||||
@@ -50,8 +39,6 @@ impl Default for RuntimeConfig {
|
||||
Self {
|
||||
fps_limit: 60,
|
||||
delta_channel_capacity: 2048,
|
||||
namespace: None,
|
||||
default_context: None,
|
||||
warm_contexts: 1,
|
||||
warm_context_ttl_secs: 20,
|
||||
}
|
||||
@@ -76,14 +63,14 @@ impl Default for UiConfig {
|
||||
|
||||
pub fn default_config_path() -> PathBuf {
|
||||
let mut base = dirs::config_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||
base.push("krs");
|
||||
base.push("krust");
|
||||
base.push("config.toml");
|
||||
base
|
||||
}
|
||||
|
||||
pub fn default_keymap_path() -> PathBuf {
|
||||
let mut base = dirs::config_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||
base.push("krs");
|
||||
base.push("krust");
|
||||
base.push("keymap.toml");
|
||||
base
|
||||
}
|
||||
+13
-6
@@ -31,10 +31,6 @@ pub async fn run() -> anyhow::Result<()> {
|
||||
kubeconfig: cli.kubeconfig.clone(),
|
||||
context: cli.context.clone(),
|
||||
all_contexts: cli.all_contexts,
|
||||
namespace: cli
|
||||
.namespace
|
||||
.clone()
|
||||
.or(app_config.runtime.namespace.clone()),
|
||||
readonly: cli.readonly,
|
||||
warm_contexts: app_config.runtime.warm_contexts,
|
||||
warm_context_ttl_secs: app_config.runtime.warm_context_ttl_secs,
|
||||
@@ -44,14 +40,24 @@ pub async fn run() -> anyhow::Result<()> {
|
||||
);
|
||||
|
||||
let contexts = provider.context_names().to_vec();
|
||||
let context_default_namespaces = contexts
|
||||
.iter()
|
||||
.map(|context| {
|
||||
(
|
||||
context.clone(),
|
||||
provider.default_namespace_for_context(context.as_str()),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let initial_context = cli
|
||||
.context
|
||||
.or(app_config.runtime.default_context)
|
||||
.or_else(|| provider.default_context().map(str::to_string))
|
||||
.or_else(|| contexts.first().cloned())
|
||||
.context("could not determine initial context")?;
|
||||
|
||||
let initial_namespace = cli.namespace.or(app_config.runtime.namespace);
|
||||
let initial_namespace = cli
|
||||
.namespace
|
||||
.or_else(|| provider.default_namespace_for_context(&initial_context));
|
||||
|
||||
let (tx, rx) = mpsc::channel(app_config.runtime.delta_channel_capacity);
|
||||
provider.start(tx).await?;
|
||||
@@ -63,6 +69,7 @@ pub async fn run() -> anyhow::Result<()> {
|
||||
contexts,
|
||||
initial_context,
|
||||
initial_namespace,
|
||||
context_default_namespaces,
|
||||
rx,
|
||||
action_executor,
|
||||
resource_provider,
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
krs::run().await
|
||||
krust::run().await
|
||||
}
|
||||
@@ -199,6 +199,7 @@ pub struct PendingConfirmation {
|
||||
pub enum Pane {
|
||||
Table,
|
||||
Describe,
|
||||
SecretDecode,
|
||||
Events,
|
||||
Logs,
|
||||
}
|
||||
|
||||
+1599
-158
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user