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 / kubernetes-data-integration

Kubernetes data integration

The Kubernetes data integration connects the application to one Kubernetes API server and turns the server's resource data into live, interactive views. It keeps the selected context, discovers the resource types that the cluster supports, retrieves objects and table data, and shares that data with views and cluster tools.

Integration boundary

The integration is the boundary between Kubernetes and the rest of the application. It gives the user a cluster-aware session without requiring the rest of the UI to understand kubeconfig files, API paths, watch recovery, or resource version rules.

The boundary provides four results:

  • a client for the selected cluster and context
  • a catalog of resource kinds that the cluster exposes
  • live object data for the current resource view
  • display data that can be joined to those objects for sorting and rendering

Connection context

Cluster session

The cluster session holds the connection and the identity used by the application for the current cluster. It also carries the default namespace, the API server address, the server revision when available, and the context name used by related cluster commands. The session is rebuilt when the user selects another kubeconfig context, so later requests and shell actions stay on the same cluster.

The application can start from the current kubeconfig context or connect to a named context. It can also keep an offline identity when the current server is unreachable, so the user can choose another context instead of treating a failed connection as a valid resource view. A server version lookup adds display metadata but does not block an otherwise healthy connection, and the stored value is safe for terminal display. src/k8s.rs• L278-315, src/k8s.rs• L430-545, src/k8s.rs• L548-607

See Kubeconfig, discovery, and authentication for context selection, authentication, and connection rules.

References: src/k8s.rs• L278-315 src/k8s.rs• L430-545 src/k8s.rs• L548-607

Request safety

The client applies common behavior to every Kubernetes request. It prevents authentication commands from taking over the interactive terminal, records request timing for diagnostics, and treats long-lived watch requests differently from short list requests. Kubeconfig proxy settings and proxy exclusions are also part of this connection boundary because they decide how the API server is reached.

These rules keep connection behavior consistent across resource views, namespace lookup, discovery, and feature-specific reads. They also make transport failures visible as connection or view errors instead of silently producing incomplete data.

References: src/k8s.rs• L33-77 src/k8s.rs• L100-224 src/…/proxy.rs• L6-36

API capability model

Resource discovery

Discovery builds the application's model of what the cluster can provide. It asks the API server for resource groups and versions, records each resource's group, version, kind, plural name, scope, aliases, list support, and scale support, then chooses one stable served version for each kind.

The discovery result drives resource navigation and namespace-aware views. It includes listable namespaced kinds as child-resource candidates, so a selected object can lead to related resources such as workloads and their pods. Custom resources enter the same model as built-in resources when the server exposes them.

The integration first uses aggregated discovery when the server supports it. It falls back to per-group discovery when needed, while retaining warnings for groups it cannot read. Empty capability results remain empty results rather than triggering an unnecessary fallback. This lets a partially available cluster remain useful without presenting unsupported resources as available.

References: src/…/discovery.rs• L11-55 src/…/discovery.rs• L58-131 src/…/discovery.rs• L133-229 src/k8s.rs• L648-657

Resource naming

Each discovered kind is addressable by its plural name, kind name, short name, or a qualified plural that includes its API group. The catalog uses these names for completion and navigation, while the registry resolves them to the group, version, and plural needed for an API request.

When names collide, the integration keeps qualified names available and gives the preferred API group the bare name. This prevents a shared kind name from opening the wrong resource while keeping common Kubernetes names fast to use. User-defined aliases are added only after their target kind is known.

References: src/k8s.rs• L241-275 src/k8s.rs• L639-713 src/k8s.rs• L715-752 src/k8s.rs• L1079-1095

Resource data flow

Live object stream

The application retrieves the full resource objects through an initial list followed by a watch. The list establishes the current set, and watch events apply changes until the connection ends or the API server requires a new list. Label and field selectors narrow the request before data reaches the application.

The stream sends object changes to the in-memory store. Each object is represented as dynamic Kubernetes data, which allows the same path to handle built-in resources and custom resources without a fixed object type for every API group. A generation marks the active view, so data from a previous resource, namespace, or context cannot replace the current view.

The integration first tries Kubernetes streaming-list startup when the cluster supports it. A capability error changes the session to the regular list-and-watch path, while authentication and server failures remain visible. An expired resource version is recoverable because the watcher re-lists and resumes. Each re-list starts a fresh store cycle, including when streaming-list recovery does not emit the usual initialization event, so objects deleted during the gap leave the view.

This diagram shows how a selected resource becomes a current interactive view.

flowchart LR
    A[Selected context and resource] --> B[API list or streaming list]
    B --> C[Initial object set]
    C --> D[Live watch events]
    D --> E[In-memory resource store]
    E --> F[Interactive views and tools]
    D -->|expired or broken stream| B
    B -->|unsupported streaming list| G[Regular list and watch]
    G --> C

References: src/k8s.rs• L754-808 src/k8s.rs• L928-949 src/k8s.rs• L959-1098 src/store.rs• L483-503

Table data

The application can request the Kubernetes server's table form for a resource. Table data contains the server's column definitions and display cells, while the object watch remains the source of the full resource objects. The application joins the two by the resource's namespace and name and checks the object identity before using cached cells.

Table data gives each resource kind a server-defined presentation without requiring the application to know every kind's status fields. If the API server does not support the table form, the integration falls back to ordinary JSON and can mark the server table as unavailable rather than treating the response as a valid table.

See Resource tables and API proxy for table columns, completion data, and API proxy behavior.

References: src/…/table.rs• L55-163 src/…/table.rs• L166-247 src/server_table.rs• L53-72 src/server_table.rs• L153-237

Interactive data model

Dynamic resource objects

The interactive model keeps Kubernetes objects in a form that preserves metadata and the resource body. Metadata supplies identity, namespace, and resource version. The body supplies fields that views, filters, timelines, and feature tools read when they need more than the server's table cells.

The store replaces an object as a whole when a newer event arrives and shares unchanged object data across the live view and related caches. This gives navigation and detail actions access to the same current object without a second read for every interaction.

References: src/store.rs• L425-438 src/store.rs• L483-503 src/store.rs• L605-671

View freshness

A resource view is a scoped snapshot of one kind, namespace, and filter set. The view combines server-side selectors with the live object stream, then drops messages that belong to an older scope. This keeps a context switch or namespace change from mixing old rows with new rows.

The same resource data supports several user actions. A view can show rows and server columns, while other features can inspect the selected object, find related objects, list namespaces, or use the active context for cluster commands.

References: src/k8s.rs• L754-808 src/store.rs• L267-299 src/store.rs• L605-671

The integration has two focused child pages:

Change checklist

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

  • Changes to the discovered Kind contract must stay aligned with resource-name resolution, completion, namespace scope, and API URL construction.
  • Changes to list or watch selectors must preserve the link between the visible scope and any action that reads or changes the selected resources.
  • Changes to object identity or resource-version handling must preserve table-cell joins and must not apply events from an older view generation.
  • Changes to connection context selection must keep direct API requests and related kubectl commands on the same cluster.
  • Changes to discovery fallback behavior must keep unavailable resources and discovery warnings distinct from an empty cluster catalog.
  • Changes to streaming-list capability checks must keep capability errors separate from authentication, authorization, throttling, and server failures.
  • Changes to optional server-version lookup must not turn missing version metadata into a failed cluster connection.
  • Changes to list-in-flight tracking must preserve a store reset for every recovered re-list, including streaming-list recovery, so objects removed during a watch gap do not remain visible.

Important failure modes

TriggerConsequenceGuard
The kubeconfig has no usable current context or the selected API server cannot be reached.The application cannot open a live resource view.Keep the cluster identity separate from the connected state and route the user to context selection when needed.
Aggregated discovery is rejected or returns an unexpected format.Some resource kinds may not be known from the first discovery attempt.Fall back to legacy per-group discovery and retain a warning about the fallback.
A discovery group has no readable versions or a group request fails.Resources in that group do not appear in navigation.Record the skipped group instead of inventing a resource definition.
The server returns a valid empty aggregated discovery result.A false fallback can add needless API requests or change the meaning of an empty catalog.Accept the empty result as the cluster's reported capability set.
A watch resource version expires.The current stream is no longer complete, and objects deleted during the gap can remain in the view.Re-list and resume the watch, and reset the store when the recovered list begins.
The server rejects streaming-list parameters.The preferred initial sync cannot start.Remember that capability result for the session and use regular list-and-watch without hiding other errors.
The server rejects table responses.Server-defined columns are unavailable for that view.Retry with ordinary JSON and mark table data unavailable rather than decoding it as a table.
A context or view changes while an old request is still active.Old data could overwrite the new view.Tag asynchronous messages with the active generation and ignore stale messages.
The optional /version request is slow or unavailable.Cluster connection can appear to fail even though discovery works, or the header lacks version text.Bound the version lookup and keep connection success independent from version metadata.

Key files

FileWhy to read it
src/k8s.rsDefines the cluster session, client setup, resource registry, list/watch entry points, namespace access, and stream recovery.
src/…/kubeconfig.rsShows how kubeconfig input becomes a usable connection configuration, including in-cluster fallback.
src/…/discovery.rsShows how API capabilities become the resource model used by the application.
src/…/table.rsShows how server table data is fetched, refreshed, watched, and downgraded when unsupported.
src/server_table.rsDefines the table columns, rows, identity checks, and join state used by resource views.
src/store.rsDefines the messages and shared object state that carry Kubernetes data into interactive views.