ktop Release v0.7.0
ktop v0.7.0 introduces an adaptive terminal theme engine with automatic background luminance and color-depth detection, refactors cluster state delivery around an immutable Snapshot pipeline and application.Runner boundary, and aligns Prometheus CPU rate and history calculations across overview and detail views.
Operators can run ktop across dark, light, 16-color ANSI, and $NO_COLOR / monochrome terminals without manual configuration, or set explicit --theme and --color-mode preferences on the command line and in ~/.ktop/config.yaml. Under the hood, overview tables and drill-down detail views render from lock-free point-in-time Snapshot projections, while the Prometheus metrics pipeline preserves upstream cAdvisor sample timestamps and series semantics to eliminate rate drift and transient 0m CPU drops.
Detailed Changes by Category
1. Adaptive Terminal Themes & UI Styling
Semantic Palette Engine and Built-in Themes
- Problem / Context: UI widgets, tables, sparklines, saturation gauges, and modal dialogs previously relied on hardcoded colors tuned only for dark TrueColor terminals, causing low-contrast text on light backgrounds, inconsistent highlights on 16-color profiles, and residual color escapes in monochrome sessions.
- Implementation Details: Added package
ui/theme(ui/theme/palette.go,ui/theme/builtins.go,ui/theme/format.go) defining a 33-token semanticPalette(CanvasBg,HeaderBg,RowSelectedBg,StatusOK..StatusError,GaugeLow..GaugeHigh,SparklineNormal,ToastInfoBg..ToastErrorBg, etc.) with four built-in themes:DarkPalette,LightPalette,ANSIPalette, andMonochromePalette. Migrated overview panels, node/pod/container detail panels, sparklines, bargraphs, filter inputs, help/column modals, and*ui.ToastModalnotifications (ui/toast.go) to resolve colors dynamically from the active palette while maintaining WCAG AA contrast (>= 4.5:1). - Impact & Behavioral Notes: Tables, headers, summary bargraphs, resource gauges, and interactive toast modals (
Retry/Quitactions and severity borders) render legibly across all four built-in palettes. Whenmonochrome(or--color-mode=none) is active,ktopemits zero ANSI color sequences and distinguishes focus, headers, selection, and error states usingAttrBold,AttrUnderline,AttrReverse, and!prefixes (ui.ErrorMarkup).
Automatic Terminal Background Detection and 4-Tier Color Quantization
- Problem / Context: Terminal emulators vary in background luminance and color capability across local consoles,
tmux, SSH sessions,TERM=dumb, and$NO_COLORenvironments. - Implementation Details: Implemented
theme.Resolve(ui/theme/detect.go) with deterministic auto-detection precedence: explicit theme override ->$NO_COLORorTERM=dumb(monochrome) ->$COLORFGBGbackground index parsing (ParseCOLORFGBG) -> non-blocking 50ms OSC 11 background query (ProbeTerminalLightBg/ParseOSC11Luminanceusing ITU-R BT.709 relative luminance) ->darkdefault. ImplementedResolveColor(ui/theme/palette.go) to quantize 24-bit RGB palette tokens to the 6x6x6xterm-256cube and 24-step grayscale ramp (ColorMode256), nearest 16-color ANSI (ColorMode16), ortcell.ColorDefault(ColorModeNone). - Impact & Behavioral Notes:
--theme=autoselects an appropriate light, dark, or monochrome theme at startup without blocking non-interactive streams or character devices that do not support read deadlines, and automatically maps palette tokens to the terminal's supported color tier.
2. CLI & Persistent Configuration
--theme and --color-mode Flags and ~/.ktop/config.yaml Persistence
- Problem / Context: Users needed session-scoped CLI overrides and persistent user defaults for theme selection and terminal color-depth degradation.
- Implementation Details: Added
--themeand--color-modeflags incmd/ktop.go(NewKtopCmd), validated byconfig.NormalizeThemeandconfig.NormalizeColorMode(config/config.go). Extendedconfig.UIConfig(ui.theme,ui.color_mode) in~/.ktop/config.yamlwithautodefaults. - APIs / Signatures:
# Automatic background and color-depth detection (default) ktop # Force light or monochrome theme ktop --theme=light ktop --theme=monochrome # Override terminal color depth for SSH or multiplexer sessions ktop --theme=dark --color-mode=256
# ~/.ktop/config.yaml ui: theme: auto color_mode: auto
- Impact & Behavioral Notes: Preferences configured under
ui.themeandui.color_modein~/.ktop/config.yamlapply automatically at startup;--themeand--color-modecommand-line flags override saved settings for the current session without mutating the config file. Unrecognized values exit immediately with a validation error listing accepted options.
3. Core Architecture & Data Pipeline
Immutable Snapshot Model and Lock-Free SnapshotBuilder
- Problem / Context: Overview panels and resource detail pages previously assembled view state separately from mutable Kubernetes models, pointer-based
resource.Quantityfields, and live metrics lookups during draw cycles. - Implementation Details: Added package
internal/snapshot(internal/snapshot/snapshot.go,internal/snapshot/builder.go) defining value-typeSnapshot,ClusterInfo,SummaryData,NodeData,PodData,ContainerData, andPSIDatastructs with deep-copyClone()and indexed accessors (NodeByName,PodByKey,PodsOnNode). Implementedsnapshot.Builder.Buildfor lock-free in-memory joins of cached controller models and batch pod/container metrics, alongsideNodeDetailProjection,PodDetailProjection, andContainerUsageFromSnapshot. Updated overview (views/overview) and detail panels (views/node,views/pod,views/container) to render fromSnapshotvalues and projections. - Impact & Behavioral Notes: Overview tables and detail pages render from a unified point-in-time state representation without performing network I/O or holding locks on the UI draw goroutine.
application.Runner Interface and application/tui Lifecycle Package
- Problem / Context: Startup orchestration in
cmd/ktop.godirectly coupled CLI flag parsing totviewpage construction, RBAC preflight checks, and terminal screen initialization. - Implementation Details: Defined the
application.Runnerinterface (Run(ctx context.Context) error,Stop() errorinapplication/app.go) and extracted interactive TUI initialization intoapplication/tui(tui.NewRunner,tui.App,tui.Optionsinapplication/tui/app.go), encapsulating theme resolution, overview layout, initial column sorting,k8sC.AssertCoreAuthz(ctx), and minimum terminal height checks. - Impact & Behavioral Notes: Cleanly separates command/configuration wiring from TUI execution while preserving existing preflight authorization diagnostics and exit behavior.
4. Prometheus Metrics & Resource Reporting
Upstream Timestamp Anchoring, Node CPU Series Selection, and Fallback Alignment
- Problem / Context: Under Prometheus scraping, node CPU metrics could disagree between Cluster Summary, the Nodes table, and the Node Detail view when cAdvisor housekeeping intervals exceeded the query window (causing transient
0mdrops), when local scrape timing jitter skewed counter rate denominators, or when root cgroup (id="/") metrics exposed bothcpu="total"and per-corecpu="0"..series. Additionally, valid0m/0Miusage was treated as missing usage data, causing views to fall back to displaying requested resources instead of0.0% used. - Implementation Details:
- Updated
KubernetesScraper(prom/scraper.go) andInMemoryStore(prom/storage.go) to record explicit upstream sample timestamps (MetricSample.UpstreamTimestamp), skip unchanged cached cAdvisor samples, and anchor stored sample timestamps using exact upstream elapsed deltas. - Added
selectNodeCPUSeriesandquerySeriesForRate(metrics/prom/prom_source.go) to filter root node CPU series (id="/") tocpu="total"(or unlabelled aggregates) when present, and fall back to a3mlookback (maxSeriesSampleAgeMs = 90s) when dynamic cAdvisor housekeeping exceeds the40srate window. - Updated
GetNodeHistoryandGetPodHistory(seriesCounterMilliRates,aggregateSeriesHistoryinmetrics/prom/prom_source.go) to convert cumulativecontainer_cpu_usage_seconds_totalcounters into per-interval millicore rates and carry forward multi-series values across staggered timestamps. - Added explicit
HasUsageCPUandHasUsageMemorybooleans acrossSummaryData,NodeData,ClusterSummary, and view renderers (views/overview/node_panel.go,views/overview/summary_panel.go,views/node/detail.go).
- Updated
- Impact & Behavioral Notes: Cluster Summary, Nodes table rows, Node/Pod Detail panels, and CPU history sparklines report consistent millicore usage rates and utilization percentages, and distinguish genuine idle usage (
0m/0.0% used) from unavailable metrics fallback (requested).
Upgrade & Compatibility Notes
- Backward Compatibility: Fully backward compatible with existing CLI invocations, kubeconfig setups, and
~/.ktop/config.yamlfiles. Existingconfig.yamlfiles withoutui.themeorui.color_modedefault toauto. - Deprecations & Retractions: None.
- Migration Actions: None required. Users running on light terminals or
$NO_COLORenvironments will automatically receive matching palettes under the default--theme=autosetting; users who prefer the classic dark palette regardless of terminal background can set--theme=darkor configureui.theme: darkin~/.ktop/config.yaml.
Workspace / Repository Metrics
56 files changed, 6858 insertions(+), 1369 deletions(-)