Introducing a new way to review your PRs.

Read the announcement

nklmilojevic / sofka

A Kubernetes TUI, reimagined in Rust - built on kube-rs and ratatui, async-first from the ground up.

View on GitHub

19 documents · Updated Nov 4, 2026

docs / configuration-and-command-line

Configuration and command-line behavior

Sofka builds each application session from command-line choices, Kubernetes context data, saved session state, and layered user settings. These inputs determine the first view, namespace scope, safety mode, diagnostics, and shell-facing behavior while keeping one-run choices separate from shared configuration.

Session inputs

The session starts with a small set of external inputs. The command line selects the launch target and can pin connection or safety behavior for the run. Kubeconfig supplies context and cluster data. Sofka state remembers choices such as the last namespace for each context.

InputSession role
Command-line optionsChoose the context, kubeconfig, resource, namespace scope, connection checks, TLS behavior, and read or write mode.
KubeconfigSupplies the current context, named contexts, cluster identity, and the namespace attached to a context.
User configurationSupplies defaults, aliases, display choices, safety rules, and feature settings.
Context overridesChange effective settings for one cluster or one context.
Saved Sofka stateRestores context-specific choices such as namespace and sort selection without changing user configuration.

The command line has priority when it names a resource or namespace. It can also force safety or connection behavior for the whole run. The session then applies effective settings for the selected cluster and context. This separation lets a user make a one-run choice without changing a shared file.

References: src/main.rs• L26-113 src/main.rs• L202-220 src/main.rs• L506-524 src/nsmem.rs• L1-9

Startup sequence

Startup turns the inputs into either an interactive terminal session or a headless command result. Sofka loads the base configuration before the first cluster request so it can start logging early. It resolves cluster and context overrides after it knows the selected target.

The main startup path follows this sequence:

  1. Handle completion, plugin adapter and validation, import, plugin-management, and release-check commands that do not need the terminal session.
  2. Apply an explicit --kubeconfig path to the process so all kubeconfig readers and shell-outs use the same source.
  3. Load the base configuration and start application logging.
  4. Connect to the selected context, or open the context picker when the user asks for ctx or contexts or when interactive connection can fall back to context selection.
  5. Resolve drop-ins and cluster or context overrides.
  6. Apply aliases, safety mode, display settings, saved state, and feature settings.
  7. Open the chosen resource and start automatic port-forwards when the session is connected.

An explicit context supplied with ctx or contexts is checked against the kubeconfig before the picker opens. The picker is interactive, so ctx and contexts cannot be combined with --check or --snapshot. An interactive connection error can lead to the context picker. --check and --snapshot instead report the error and exit because they have no screen in which to recover.

The diagram shows how launch inputs become a running session or a headless result.

flowchart TD
    A[Command line] --> B{Shell-facing or validation command?}
    B -->|Yes| C[Run command and exit]
    B -->|No| D[Load base configuration]
    D --> E[Start logging]
    E --> F[Select kubeconfig and context]
    F --> G{Interactive or headless run?}
    G -->|Headless| H[Report result and exit]
    G -->|Interactive| I[Resolve cluster and context settings]
    I --> J[Restore saved session state]
    J --> K[Open resource view]

References: src/main.rs• L150-200 src/main.rs• L243-329 src/main.rs• L373-534

Configuration sources

The configuration system provides a base file and optional layers. Sofka looks under $XDG_CONFIG_HOME/sofka, with ~/.config/sofka as the usual fallback. An empty XDG_CONFIG_HOME is treated as unset, so it does not create a relative configuration path. The same setting model works in TOML and YAML.

The effective configuration is built in this order:

  1. Base configuration.
  2. Files in conf.d/, sorted by file name.
  3. A cluster-level file under clusters/<cluster>/.
  4. A context-level file under clusters/<cluster>/<context>/.
  5. User and bundled plugin packages.

Cluster and context names map to safe directory names. A cluster layer applies to every context on that cluster. A context layer applies only to its named kubeconfig context. The loader reads override layers again during a context switch, so the active context can change its settings without a process restart.

Tables merge by key. Scalar values and arrays replace inherited values. Inline plugins can use name-based merging when a shared layer and a personal layer must combine entries. Each document is checked before it enters the effective configuration. Invalid base configuration falls back to defaults at startup. Invalid drop-ins and override layers are skipped with warnings. If an override makes the merged typed configuration invalid, Sofka keeps the valid base configuration instead of discarding the whole session.

See Configuration documents and migrations for file format, merge rules, and configuration evolution.

References: src/config.rs• L1-24 src/config.rs• L1361-1484 src/config.rs• L1486-1592 src/config.rs• L1595-1660 src/config.rs• L1762-1793

Launch selection

Launch selection determines the first context, namespace scope, and resource view. The positional resource and --resource are equivalent choices. If neither is present, Sofka uses default_resource and then falls back to pods.

The ctx and contexts resource names select the interactive context picker instead of a resource view. An explicit --context narrows that picker to a named kubeconfig context, and Sofka rejects the launch if that name does not exist.

Namespace selection is a policy rather than a single setting. The normal order is:

  1. An explicit -n or --namespace, or -A for all namespaces.
  2. The kubeconfig namespace when prefer_context_namespace is enabled.
  3. The saved namespace for the selected context.
  4. default_namespace from effective configuration.
  5. The Kubernetes namespace fallback.

Namespace picks are saved per kubeconfig context in the state directory. This state is separate from user configuration, so normal navigation does not rewrite the configuration file. A saved all-namespaces choice remains a valid scope.

References: src/main.rs• L202-239 src/main.rs• L578-597 src/main.rs• L1088-1107 src/nsmem.rs• L19-99

Safety mode

Safety mode controls whether the session can perform actions that change the cluster or run commands. Configuration can set readonly for all sessions or for a specific cluster or context. The --readonly and --write flags override that setting for the whole process, and the two flags cannot be used together.

The mode is fixed by the CLI when one of those flags is present. Without a CLI override, Sofka re-resolves the configured mode when the user changes context. This lets a production override stay read-only while a session follows the safety policy of each target context.

References: src/main.rs• L75-84 src/main.rs• L569-577 src/config.rs• L61-73

Runtime changes

The command palette can reload configuration during an interactive session. A successful reload applies settings that affect later views or context changes and refreshes active configuration warnings. A failed base reload keeps the last valid base configuration. Override errors remain visible as warnings and do not stop the application.

Not every setting has the same lifetime. Some values seed the session and remain under live user control after a reload. Context-scoped values are read again when the context changes. Saved navigation state has its own lifetime because it persists outside the configuration files.

Use :config to inspect selected sources and warnings when effective behavior is not clear. Use :reload after editing configuration or plugin packages.

References: src/config.rs• L1396-1415 src/config.rs• L1473-1483 src/config.rs• L1545-1577 src/main.rs• L449-451

Shell-facing commands

Sofka has command paths for scripts, shells, diagnostics, configuration import, plugin management, and release checks. completion prints a shell script without loading configuration or connecting to a cluster. info reports build, configuration, connection, discovery, logging, and directory state. plugin manages reviewed plugin packages and can produce machine-readable output. import converts another tool's configuration into Sofka configuration files, while check-update reports a newer release and an upgrade hint without installing it.

The explicit --kubeconfig path affects the whole process. This keeps Sofka's Kubernetes client, context inspection, completion queries, and kubectl-backed actions aligned on one kubeconfig source. The hidden plugin adapter and plugin validation paths also exit before normal session setup so they can use stdout for their own reports.

Completion can query the selected kubeconfig, context settings, Kubernetes discovery, namespaces, and the plugin catalog. These lookups are bounded and quiet. If cluster data is unavailable, the shell receives no completion error output.

See Shell completion for shell setup and supported completion values.

References: src/main.rs• L115-200 src/main.rs• L243-289 src/main.rs• L741-750 src/main.rs• L777-841 src/completion.rs• L15-107 src/plugin_cli.rs• L14-77

Headless operation

Headless modes let automation inspect or render a session without taking over a terminal. --check connects, performs discovery, checks namespace access, and prints a summary. --snapshot renders one resource frame without requiring a TTY. info --offline reports local state without attempting a cluster connection, while info can connect briefly to include live cluster and watch health data.

These modes use the same launch choices as an interactive session where possible. In particular, info resolves the same resource and namespace that the selected flags would open and probes that watch when a connection is available. It reports connection problems as part of the diagnostic output so the command can explain a broken setup instead of hiding useful local details behind an early failure. The deprecated top-level --info spelling keeps the offline diagnostic behavior.

References: src/main.rs• L86-106 src/main.rs• L880-1085 src/main.rs• L544-547 src/main.rs• L607-611 src/main.rs• L777-985

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to CLI launch precedence must stay aligned with the namespace and resource choices reported by info and used by completion.
  • Changes to kubeconfig selection must preserve the process-wide KUBECONFIG contract for client reads and kubectl-backed actions.
  • Changes to configuration merge order must keep base, drop-in, cluster, and context resolution consistent across startup, reload, context switches, and read-only completion lookup.
  • Changes to readonly or --write behavior must preserve the distinction between a session-wide CLI pin and a context-specific configuration value.
  • Changes to saved namespace state must keep the all-namespaces spelling compatible with disk state and namespace resolution.
  • Changes to shell-facing output must preserve script-only stdout and diagnostic output on stderr where shell integration depends on it.
  • Changes to the configuration directory rules must keep empty XDG_CONFIG_HOME values on the home-directory fallback path.
  • Changes to context-picker validation must keep ctx and contexts interactive and must validate an explicit --context against the selected kubeconfig.
  • Changes to info must keep its launch-resource and namespace report aligned with the session that the same flags would start.

Important failure modes

TriggerConsequenceGuard
More than one supported base, cluster, or context config file exists at one levelThat configuration level reports a conflict and does not provide a clean sourceKeep one config.toml, config.yaml, or config.yml at each level
Base configuration is malformed or has a type errorStartup uses defaults; a failed reload keeps the last valid baseCheck :config warnings and validate the edited file before reload
An override file is invalid or makes the merged config invalidThe bad override is skipped or effective settings fall back to the baseFix the named override and reload; do not assume partial values were applied
--readonly and --write are both suppliedArgument parsing rejects the launchSelect one session safety mode
ctx or contexts is combined with --check or --snapshotArgument validation rejects the launch because the picker needs an interactive sessionRemove the headless flag or choose a concrete resource
An explicit --context is not present in the kubeconfig during context-picker launchThe picker does not start and reports the missing contextUse a context name from the selected kubeconfig
Completion needs cluster data but the selected context cannot list namespaces or discover APIsNo dynamic candidates are returned, with no shell errorVerify kubeconfig, credentials, context selection, and API permissions
Completion invokes a slow or interactive credential helperThe completion request is bounded and returns no candidatesUse a non-interactive helper that completes within the request limit
The selected context cannot connect in a headless mode--check or --snapshot exits with an error instead of opening a pickerTest the same context with sofka info or use interactive context selection

Key files

FileWhy to read it
src/main.rsDefines the CLI surface and turns launch inputs into interactive, diagnostic, or headless behavior.
src/config.rsDefines the configuration model, source layers, effective merge behavior, reload behavior, and warning policy.
src/…/document.rsExplains TOML and YAML document selection and parsing at each configuration level.
src/nsmem.rsShows how namespace choices persist per context and enter launch precedence.
src/completion.rsDefines dynamic shell completion behavior and its bounded cluster lookups.
src/plugin_cli.rsDefines shell-facing plugin management commands and their user-visible outcomes.
docs/configuration-documents-and-migrations.mdChild page for configuration formats, migration behavior, and layer evolution.
docs/shell-completion.mdChild page for shell setup and completion behavior.