Introducing a new way to review your PRs.

Read the announcement

replicatedhq / troubleshoot

Preflight Checks and Support Bundles Framework for Kubernetes Applications

View on GitHub

19 documents · Updated Nov 20, 2026

docs / kubernetes-utilities-and-client-services

Kubernetes utilities and client services

The shared service layer gives workflow execution one set of boundaries for talking to Kubernetes, loading workflow specifications, reaching external registries and URLs, checking cluster state, and reporting useful run identity. It keeps these cross-cutting concerns separate from the higher-level collection, preflight, and analysis flows described in Kubernetes integration and runtime.

System role

Workflow execution needs more than a Kubernetes API call. It must turn user and cluster inputs into typed specifications, use the right access scope, move data across trusted external interfaces, and expose enough status to explain a run. These packages provide those shared services so the workflow layers can focus on what to collect or check.

The services connect in this broad order:

flowchart LR
    A[CLI or workflow request] --> B[Specification loading]
    B --> C[Typed workflow kinds]
    C --> D[Kubernetes and host workflow execution]
    D --> E[Cluster checks and network probes]
    B --> F[HTTP and OCI sources]
    D --> G[Logs and build identity]

Shared service boundaries

Kubernetes client access

The client layer provides a common, typed entry point to the Troubleshoot API group and Kubernetes discovery. A client created from one REST configuration shares its transport across the supported Troubleshoot API versions, so workflow services use one connection model while still addressing version-specific resources. pkg/…/clientset.go.

The clientset also has a fake form for isolated service checks. This lets callers model API objects and actions without requiring a live cluster, while the real client remains the boundary for cluster-backed workflows.

References: pkg/…/clientset.go• L32-45 pkg/…/clientset.go• L70-123 pkg/…/clientset_generated.go• L36-69

Specification loading

The loader turns raw YAML documents into a single typed collection of workflow kinds. It accepts multi-document input, extracts supported data from Kubernetes Secrets and ConfigMaps, recognizes supported Troubleshoot API versions, and produces a common v1beta2 result for downstream workflow execution. The v1beta3 SupportBundle path preserves the shared workflow specification while resolving Secret and ConfigMap references into the values used by execution. pkg/…/loader.go.

Loading can be permissive or strict. In permissive mode, invalid or unrelated documents do not prevent valid workflow definitions from being used. A Kubernetes client and namespace are needed when a v1beta3 SupportBundle refers to values in a Secret or ConfigMap; without that access, the loader reports that the workflow needs cluster-backed resolution.

References: pkg/…/loader.go• L40-94 pkg/…/loader.go• L96-130 pkg/…/loader.go• L171-237 pkg/…/loader.go• L240-361 pkg/…/supportbundle_v1beta3_preservation_test.go• L14-112

Specification source coordination

The internal specification service combines the loader with the sources used by CLI workflows. It accepts local files, standard input, named Kubernetes objects, HTTP URLs, OCI application references, and optional objects discovered in the cluster. internal/…/specs.go.

The service keeps source-specific concerns at the edge. It gathers raw documents first, loads them through the shared loader, and merges the resulting typed kinds. Cluster discovery uses labels and adapts its search scope to the caller's permissions. This allows a workflow to use the broadest safe search available instead of assuming cluster-wide access.

References: internal/…/specs.go• L72-76 internal/…/specs.go• L85-237 internal/…/specs.go• L271-374

Kubernetes utility services

The Kubernetes utility package supplies small decisions that many workflows need: building REST and kubeconfig access from shared CLI flags, checking access to cluster-wide Secrets and ConfigMaps, testing API resource support, classifying node readiness, and interpreting pod health. pkg/…/config.go, pkg/…/auth.go, pkg/…/discovery.go, pkg/…/node.go, and pkg/…/pod.go.

These helpers turn raw Kubernetes state into workflow decisions. For example, cluster specification loading uses an access review before it selects a namespace search plan, while execution can use a stable pod reason and health result instead of interpreting container state itself.

References: pkg/…/config.go• L14-27 pkg/…/auth.go• L11-51 pkg/…/discovery.go• L7-29 pkg/…/node.go• L5-20 pkg/…/pod.go• L49-185

Remote command transport

The remote command helper gives workflow code one executor that prefers WebSocket and can fall back to SPDY when the Kubernetes server or an HTTPS proxy cannot use the first transport. pkg/…/exec.go.

This boundary protects collection and diagnostic flows from transport choice. Callers ask to run a command against a Kubernetes endpoint and receive the same executor shape across supported server and proxy paths.

References: pkg/…/exec.go• L11-26

Network namespace services

The namespace package creates short-lived Linux network environments for network checks that must run from a controlled source address. A managed namespace joins a virtual interface pair, assigns internal and external addresses, sets a route, and provides TCP and UDP echo probes. pkg/…/managed-namespace.go and pkg/…/namespace-pinger.go.

The service restores the caller's original network namespace after each operation and removes its temporary resources when closed. On non-Linux systems, the same probe surface returns an explicit unsupported-platform error instead of pretending that the check ran. pkg/…/network-namespace.go and pkg/…/managed-namespace_unsupported.go.

When a network probe runs, the relationship between the workflow and the temporary network environment is:

sequenceDiagram
    participant W as Workflow
    participant N as Namespace service
    participant T as Target
    W->>N: Create managed network environment
    N->>N: Attach interface and set route
    W->>N: Start TCP or UDP echo server
    W->>N: Send probe from namespace
    N->>T: Reach target
    T-->>N: Echo response
    N-->>W: Probe result
    W->>N: Close and restore environment

References: pkg/…/managed-namespace.go• L24-97 pkg/…/network-namespace.go• L27-35 pkg/…/network-namespace.go• L55-115 pkg/…/namespace-pinger.go• L17-75 pkg/…/managed-namespace_unsupported.go• L16-42

OCI specification retrieval

The OCI service retrieves published preflight and support-bundle specifications from the OCI reference used by a KOTS application. It selects the matching Troubleshoot media type from the release content and returns the raw specification for normal loading. pkg/…/pull.go.

A reference can yield either or both supported specification types. A missing preflight does not block a support-bundle load, and a missing release is reported as a distinct condition so the CLI can give source-specific guidance. Registry credentials are taken from the Helm registry configuration first, with Docker credentials as the fallback.

References: pkg/…/pull.go• L32-75 pkg/…/pull.go• L78-191 pkg/…/pull.go• L194-219 internal/…/specs.go• L153-170

HTTP source access

HTTP access supports workflows that fetch specifications from URLs. The CLI source coordinator uses a bounded client for these downloads, applies source-specific headers when needed, reads the response under the request context, and passes the result to the common loader. internal/…/specs.go.

The shared pkg/httputil service exposes a common client when a caller has supplied a custom transport. It is the transport hook for code that needs consistent HTTP behavior without creating a separate client for each request. pkg/…/config.go.

References: internal/…/specs.go• L68-70 internal/…/specs.go• L240-268 pkg/…/config.go• L7-23

Logging controls

The logging service gives command-line entry points and libraries one way to control klog verbosity. Quiet mode suppresses routine framework output, while debug mode or an explicit verbosity value enables progress and diagnostic messages. pkg/…/logger.go.

The service separates message importance into broad levels. High-level workflow progress belongs at a lower verbosity than detailed component data, and functions that return errors leave error reporting to their callers. This keeps library calls composable and prevents the same failure from being logged at several layers.

References: pkg/…/logger.go• L1-16 pkg/…/logger.go• L32-80 pkg/…/logger.go• L83-94

Build identity

The version service gives each workflow run a shared product identity. It records the release version, shortened source revision, build time, Go runtime details, and run time, then exposes the version as a user-agent value and as a small Troubleshoot-formatted version document. pkg/…/version.go.

That identity travels with external calls and support-bundle metadata. It helps registry and API services identify the caller and gives downstream bundle readers a way to relate an artifact to the binary that created it.

References: pkg/…/version.go• L18-33 pkg/…/version.go• L35-69 pkg/…/version.go• L71-119 pkg/…/pull.go• L111-119

Workflow service flow

The services form a shared path rather than a second workflow engine. A command first resolves its specification sources, then the loader normalizes the result, and execution services use Kubernetes and network helpers only where the selected workflow needs them.

  1. A command supplies a specification source or asks to discover one in the cluster.
  2. Source coordination reads the source and sends raw documents to the loader.
  3. The loader validates supported documents and returns typed workflow kinds.
  4. Kubernetes utilities establish access, resource, pod, and node decisions for execution.
  5. OCI and HTTP services provide any later specification referenced by a loaded workflow.
  6. Logging and version services expose progress and run identity to operators and downstream artifacts.

This separation means a workflow can change its source without changing its execution contract. It also means cluster permissions, platform support, transport errors, and source errors remain visible at the boundary where they occur.

Change checklist

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

  • Changes to supported Troubleshoot API versions must stay aligned across the clientset, scheme registration, loader decoding, and the typed result consumed by workflow runners.
  • Changes to Secret or ConfigMap discovery must preserve both label compatibility paths and the permission-based namespace search behavior.
  • Changes to v1beta3 value references must preserve the contract that a Kubernetes client and the correct namespace are required for cluster-backed resolution.
  • Changes to v1beta3 SupportBundle conversion must preserve the shared workflow specification after reference resolution.
  • Changes to OCI media types, image names, or URI rules must stay aligned with the release publisher and the CLI's missing-release error path.
  • Changes to network namespace setup must preserve cleanup and restoration of the caller's original namespace, especially on error paths.
  • Changes to user-agent or version fields must be checked against both external registry requests and support-bundle version metadata.

Important failure modes

TriggerConsequenceGuard
A v1beta3 SupportBundle uses a Secret or ConfigMap reference without a Kubernetes clientThe specification cannot be resolved and the workflow cannot startProvide a cluster client and its target namespace to the loader
The caller cannot read cluster-wide Secrets and ConfigMapsCluster discovery may miss definitions or fall back to a narrower namespace searchUse the access review and namespace fallback path in the specification service
An OCI reference has no matching release or supported media layerNo remote workflow specification is availableCheck the distinct no-release result and verify the application reference
A namespace probe runs on a non-Linux platformThe probe returns an unsupported-platform errorSelect a platform-supported execution path before requesting the probe
A temporary network namespace is not closed after a probeNetwork interfaces or namespace state can remain behind and affect later checksTreat namespace cleanup and restoration as part of the probe lifecycle
A Kubernetes API server does not support the first remote command transportCommand execution can fail if no fallback is usedUse the fallback executor for WebSocket upgrade or proxy failures

Key files

FileWhy to read it
internal/…/specs.goShows how CLI sources, cluster discovery, the loader, HTTP, and OCI retrieval are joined.
pkg/…/loader.goDefines the common boundary from raw documents to typed workflow kinds.
pkg/…/supportbundle_v1beta3_preservation_test.goShows that v1beta3 reference resolution preserves the shared SupportBundle specification.
pkg/…/clientset.goShows the shared Kubernetes client contract across Troubleshoot API versions.
pkg/…/auth.go and pkg/…/config.goExplain how cluster access and permissions shape workflow setup.
pkg/…/pod.go and pkg/…/discovery.goShow how raw cluster state becomes execution decisions.
pkg/…/managed-namespace.go and pkg/…/namespace-pinger.goExplain the controlled network environment used by network checks.
pkg/…/pull.goDefines the OCI contract for published preflight and support-bundle specifications.
pkg/…/config.goShows the shared HTTP transport hook.
pkg/…/logger.goDefines operator-facing verbosity and quiet-mode behavior.
pkg/…/version.goDefines the run identity used by requests and bundle metadata.