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 / resource-tables-and-api-proxy

Resource tables and API proxy

Resource tables turn Kubernetes objects and cluster-provided display data into the rows that users inspect in the terminal. The same cluster client also supports live metrics, shell completion values, and access to in-cluster HTTP services through the Kubernetes API server.

Resource table model

The resource view keeps two related data streams: full Kubernetes objects for details and actions, and display cells for columns that Kubernetes or the application computes. This split lets the table update quickly without losing the complete object needed for navigation or inspection.

flowchart LR
    D[API discovery] --> R[Resource kind]
    R --> O[Full object list and watch]
    R --> C[Column sources]
    C --> V[Visible table]
    O --> V
    M[Metrics snapshots] --> C
    T[Kubernetes Table API] --> C
    P[Configured or CRD columns] --> C

For a resource kind, the view selects the best available column source. User-defined views take precedence, followed by built-in views, CRD printer columns, server-provided Table columns, and finally the basic NAME/AGE view. The order preserves useful Kubernetes-specific data while still giving an unknown or aggregated resource a usable table.

The full-object stream starts with an initial list and then stays current through a watch. The client can use Kubernetes streaming-list startup when the cluster supports it, but records an unsupported capability and falls back to the normal list-then-watch path for later views. Watch messages carry a view generation so the application can discard events from an older resource view. A reconnect or re-list resets the table before new objects arrive, which prevents deleted objects from remaining visible.

Resource discovery and completion

Resource discovery builds the catalog that powers resource resolution and completion. It reads the API groups and versions served by the cluster, keeps listable resources, records scope and write capabilities, and retains short names so the same resource can be reached by plural, kind, qualified name, or alias.

The catalog is also exposed through a light completion path. Resource completion reads discovery data without starting watches or loading the terminal application, while namespace completion reads the current namespace list. This keeps command completion tied to the active cluster rather than to a fixed local list.

The discovery result prefers one stable served version for each group and kind. A failure in the newer aggregated discovery path can fall back to older per-group discovery, so a partial discovery problem does not silently make the cluster appear to have no resources. Resource registration then gives higher-priority API groups control of ambiguous bare names, while qualified names remain available for the other resource.

References: src/…/discovery.rs• L11-55 src/…/discovery.rs• L133-203 src/…/completion.rs• L3-38 src/k8s.rs• L648-713

Column source priority

Column construction combines static layout rules with data that arrives from the cluster. The selected view controls the shape of the table, while each source supplies values for that shape.

SourceMain purposeWhen it is used
User viewCustom paths, built-in fields, and metric fieldsAlways wins when valid configuration exists
Built-in viewUseful columns for core resourcesUsed when no user column replaces it
CRD printer columnsOperator-defined columns for custom resourcesUsed when no explicit user view exists
Kubernetes Table APIColumns supplied by an aggregated or custom APIUsed when the other sources provide no usable layout
NAME/AGE fallbackBasic identity and ageUsed when no richer column source is available

CRD printer columns inherit their display type and wide-mode priority from the CRD. Condition expressions can become condition columns, which makes common readiness fields readable without a separate view. Explicit views still control the final layout when a user needs a different presentation.

References: src/views.rs• L1052-1109 docs/views.md• L437-469 src/…/server_table.rs• L290-315

Server-provided columns

The Kubernetes Table API supplies a meta.k8s.io/v1 table when the resource itself can provide display rows but the application has no better local layout. It is useful for aggregated APIs and for resources whose CRD definition cannot be read.

The full resource watch remains authoritative for object data. Table cells are matched to objects by identity and resource version, so stale display data is not shown for a changed object. A missing or failed Table response removes only those extra cells and leaves the full resource table available.

Table data follows the active namespace and label or field selectors. It can arrive through a Table watch, or through periodic list requests when the API does not support Table watches. Relative time values are refreshed as the Table feed is renewed.

References: src/…/table.rs• L16-22 src/…/table.rs• L98-163 src/…/table.rs• L166-247 src/server_table.rs• L67-141 src/server_table.rs• L153-237

Column and metric presentation

Columns give the resource table a common way to show identity, state, quantities, and live usage. Values can come from object paths, built-in resource views, or metric snapshots, and the table uses the value type for sorting and filtering rather than only the rendered text.

Custom and built-in columns

A custom column reads a JSON path from the Kubernetes object and can render text, status, numbers, quantities, times, or conditions. Built-in columns preserve computed fields such as readiness and age, while a wide column stays hidden until the user requests more detail.

A view can overlay the built-in layout or replace it. Overlay mode keeps useful default columns and inserts or replaces matching headers. Replace mode makes the declared columns the complete layout, except for the namespace column needed in all-namespaces mode. Invalid or unsupported column definitions produce warnings and do not stop the table.

References: docs/views.md• L3-49 docs/views.md• L119-155 src/views.rs• L1052-1109

Live metric columns

Metric columns add current usage and resource context to pod and node tables. Usage comes from the metrics API, while request and limit totals come from the resource object, so request and limit columns can still show data when a metrics server is absent.

The supported metric groups are:

  • Pod and node CPU or memory usage.
  • Pod request and limit totals.
  • Pod usage as a percentage of requests or limits.
  • Node pod counts.
  • Node CPU and memory use as a percentage of allocatable capacity.
  • Node CPU and memory trend columns.

Pod totals represent application containers and native sidecars after startup. Pod-level declarations take priority. Regular init containers and pod overhead do not enter these totals, so the values describe workload use rather than the complete scheduling calculation.

Node utilization and trend columns use node allocatable CPU or memory as their capacity basis. Percentage columns keep the numeric value for sorting and structured filters, while the rendered value uses CPU, memory, count, or percentage units. Missing data stays visible as unknown instead of becoming zero. Metric columns update when a new metrics sample arrives.

References: src/columns_metrics.rs• L8-25 src/columns_metrics.rs• L27-59 src/columns_metrics.rs• L62-103 src/columns_metrics.rs• L105-137 src/columns_metrics.rs• L141-176 docs/views.md• L157-197

Completion data

Completion values use the active cluster catalog. The catalog supplies plural and group-qualified resource names, while the resolver also accepts lower-case kinds, built-in aliases, and API short names; namespace completion instead returns names from the cluster's namespace list.

This path is intentionally separate from the interactive table lifecycle. It creates a client and performs only the request needed for completion, so completion does not open resource watches or depend on in-memory TUI state.

References: src/…/completion.rs• L3-38 src/k8s.rs• L297-299 src/k8s.rs• L660-713

API proxy support

Proxy support lets cluster requests work in environments where the API server or an in-cluster service is reachable only through an approved network path. The connection uses the selected kubeconfig context and keeps the normal Kubernetes client authentication for requests made through that path.

Cluster endpoint proxy rules

The cluster client honors an explicit proxy-url from the selected kubeconfig cluster. When that setting is absent, NO_PROXY or no_proxy can exclude the Kubernetes API server from the environment proxy. The upper-case variable has priority when it contains a non-empty value.

Exclusions can match all hosts, host names, subdomains, IP addresses, IP networks, and ports. Matching is based on the API server host and effective port, so a port-specific rule does not unintentionally disable the proxy for a different endpoint.

References: src/…/proxy.rs• L6-35 src/…/proxy.rs• L38-117

Kubernetes service proxy

The Kubernetes API server can also proxy HTTP requests to a Service inside the cluster. This is used for optional backends such as Prometheus-compatible metrics services and VictoriaLogs when no direct endpoint is configured. The application discovers a matching Service, then sends path-only requests through the API server with the active Kubernetes session.

This path avoids assuming that a Service ClusterIP is reachable from the user's workstation. A direct URL remains available when the backend is exposed outside the cluster, and explicit provider configuration takes precedence over in-cluster service discovery.

sequenceDiagram
    participant App
    participant API as Kubernetes API server
    participant Svc as In-cluster Service
    participant Backend as Metrics or log API
    App->>API: List matching Services
    API-->>App: Service name, namespace, and port
    App->>API: Request /api/v1/namespaces/.../services/.../proxy
    API->>Svc: Forward request
    Svc->>Backend: Serve query or stream
    Backend-->>App: Response through API server

Metrics discovery finds Prometheus or VictoriaMetrics services and uses their query API for historical analysis. Log discovery finds VictoriaLogs services and uses the same proxy form for history and live tails. Both integrations fail with a clear configuration prompt when no matching service exists and no direct URL is set.

References: src/providers.rs• L99-117 src/providers.rs• L379-417 src/providers.rs• L720-744 src/providers.rs• L1101-1129 src/providers.rs• L1217-1245 docs/providers.md• L29-31 docs/providers.md• L58-60

Change checklist

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

  • Keep the column-source priority aligned across user views, CRD printer columns, server Tables, and the NAME/AGE fallback.
  • Keep server Table cell identity checks aligned with the full resource watch so cells cannot outlive the object version they describe.
  • Keep metric names, supported resource kinds, rendered units, sorting, and structured filter headers consistent. Include node trend columns when the metric set changes.
  • Keep pod resource totals aligned with pod-level declarations, native sidecars, and the exclusion of init peaks and overhead.
  • Keep discovery aliases and completion values aligned so a value suggested by completion resolves to the same API resource.
  • Keep proxy URL precedence and environment exclusion behavior aligned with the context selected from kubeconfig.
  • Keep service discovery selectors, service ports, and API-server proxy paths aligned with the supported metrics and log backends.
  • Keep streaming-list capability state shared across watches, and keep fallback limited to API responses that reject the streaming-list feature.
  • Keep watch generations and re-list resets aligned with the table store so events from an old view or an earlier list cannot repopulate the current table.

Important failure modes

TriggerConsequenceGuard
An API does not support the Kubernetes Table media typeThe resource keeps its full-object view without server columnsRetry with ordinary JSON and use the NAME/AGE or other local view
A Table cell belongs to an older UID or resource versionA stale value could describe the wrong objectMatch cells to the current object identity before display
Metrics data is missing or a request or limit is zeroUsage percentages are unknown rather than meaningfulRender an unknown value and keep absolute object-derived totals where available
A pod resource field is missing while a total needs all limitsThe related total or utilization cannot be treated as completeKeep the value unknown instead of treating a missing resource as zero
Aggregated API discovery fails or an API group is incompleteSome resources may be missing from the catalogFall back to per-group discovery and report skipped groups
A cluster rejects streaming-list parametersInitial resource loading fails if the extension is retried on every viewMark the capability unsupported and use the normal list-then-watch flow
A watch reconnect starts a new list without clearing old rowsObjects deleted during the gap can remain on screenReset the generation's rows before applying the re-listed objects
No discovered metrics or log Service matches the known selectorsThe optional backend cannot be reached through the clusterReport the missing Service and request a direct provider URL
A proxy or load balancer closes a long-lived watchThe table may stop receiving live changesRefresh the feed and fall back to polling when watch support is unavailable

Key files

FileWhy to read it
src/k8s.rsConnects discovered resource kinds to full-object watches, Table feeds, aliases, completion data, and the active cluster client.
src/…/discovery.rsDefines the cluster resource catalog and its aggregated-discovery fallback.
src/…/completion.rsShows how resource and namespace completion values come from the active cluster.
src/…/table.rsShows the Table API list and watch lifecycle, selectors, refresh timing, and fallback behavior.
src/server_table.rsDefines how server columns and cells are matched to live resource objects.
src/views.rsDefines object-path and CRD printer-column presentation.
src/columns_metrics.rsDefines metric kinds, supported resources, totals, utilization, and trend presentation.
src/…/proxy.rsDefines kubeconfig proxy precedence and environment proxy exclusions.
src/providers.rsDefines direct and Kubernetes API-server proxy access for metrics and log services.
docs/views.mdDescribes the user-facing rules for custom, built-in, CRD, server, and metric columns.
docs/providers.mdDescribes the user-facing metrics and log provider paths that can use the service proxy.