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-integration-and-runtime

Kubernetes integration and runtime services

Troubleshoot uses a shared runtime layer to connect workflow commands with Kubernetes, node environments, remote endpoints, container registries, and support-bundle sources. The layer gives collection, preflight, and bundle workflows common rules for access, source loading, authentication, time limits, cleanup, and result handling.

Runtime boundary

The runtime boundary turns user or specification input into a controlled workflow context. It supplies Kubernetes access, resolves external sources, starts work in the right execution location, and returns data or clear failure information to the workflow above it.

The main runtime responsibilities are:

ResponsibilitySystem behavior
Cluster accessUses the active Kubernetes configuration and standard Kubernetes clients.
Specification accessReads local input, Kubernetes objects, HTTP locations, or OCI content.
Value accessResolves selected values from Secrets and ConfigMaps when a specification needs them.
Remote executionRuns host checks on selected nodes through short-lived Kubernetes workloads.
External accessApplies shared HTTP, TLS, registry, and retry behavior to remote calls.
Safety checksChecks permissions, limits work with contexts or timeouts, and removes temporary objects.

The runtime supports both in-cluster and command-line use. A workflow can pass an existing client or REST configuration when it needs shared access. Command-line entry points can build that access from Kubernetes flags.

References: pkg/…/config.go• L10-27 pkg/…/clientset.go• L32-44 pkg/…/collect.go• L26-38

Kubernetes access

Kubernetes access is the common path for reading cluster state and starting work in the cluster. The standard client covers core resources, while the Troubleshoot client set exposes the Troubleshoot API versions through the same REST configuration.

The access model separates three concerns:

  • Configuration selects the cluster, user, and namespace context.
  • Clients provide typed access to Kubernetes resources and Troubleshoot resources.
  • Discovery and authorization show whether a resource exists and whether the current identity can perform a required action.

This separation lets a workflow fail before it starts a collector when the cluster lacks a needed resource or permission. It also lets cluster-wide source loading reduce its scope when the current identity cannot read every namespace.

References: pkg/…/config.go• L18-27 pkg/…/clientset.go• L70-123 pkg/…/discovery.go• L7-29 pkg/…/auth.go• L11-51

Kubernetes client access

The Kubernetes client access page describes how workflows obtain standard and Troubleshoot clients and how those clients share one cluster configuration. Read it when a change affects API version registration, client construction, or the boundary between a REST configuration and a typed client.

References: pkg/…/clientset.go• L32-44 pkg/…/clientset.go• L75-123 pkg/…/register.go• L31-59

Kubernetes helper services

The Kubernetes helpers page describes the shared checks and actions used by collectors. These helpers cover node selection, pod health, remote command streams, and resource discovery so that workflows use the same interpretation of cluster state.

References: pkg/…/pod.go• L9-26 pkg/…/pod.go• L49-185 pkg/…/node.go• L5-20 pkg/…/exec.go• L11-26 pkg/…/discovery.go• L7-29

Source loading

Source loading turns several input forms into a common set of Troubleshoot specifications. It accepts YAML documents, extracts supported Troubleshoot kinds, reads embedded data from Kubernetes Secrets and ConfigMaps, and keeps unrelated documents out of the workflow.

The loading path also handles references that need cluster access. A v1beta3 support-bundle specification can point to a Secret or ConfigMap value. The loader resolves that value before it converts the specification to the internal workflow form. Required references fail the load; optional references can produce an empty value. The v1beta3 path preserves the shared support-bundle behavior while it resolves these values.

The Specification loading and resolution page describes this source boundary in more detail. The Kubernetes utilities and client services page covers the related cluster access and helper services.

References: pkg/…/loader.go• L40-93 pkg/…/loader.go• L171-237 pkg/…/loader.go• L308-361 pkg/…/resolver.go• L11-117 pkg/…/converter.go• L11-39 pkg/…/supportbundle_v1beta3_preservation_test.go• L14-112

Bundle source types

Support-bundle and preflight workflows can combine sources instead of relying on one fixed location. The source layer supports direct input, files, standard input, Kubernetes objects, HTTP URLs, OCI references, and specifications discovered in labeled cluster objects.

The flow is tolerant of partial source results in the places where a missing optional source should not hide valid work. A remote source can be added to the loaded set, and a cluster lookup can fall back to narrower namespace access when broad access is not available.

References: internal/…/specs.go• L72-237 internal/…/specs.go• L271-374 pkg/…/load.go• L151-263

OCI bundle sources

OCI bundle sources provide published preflight and support-bundle specifications from a registry. The source layer selects the specification content by its media type and uses the local Helm or Docker credential store when the registry needs credentials.

The Bundle source loading page explains how HTTP, OCI, Secret, ConfigMap, and cluster sources enter the common loader. A missing OCI release is reported as a source problem so the caller can distinguish it from a general registry failure.

References: pkg/…/pull.go• L32-75 pkg/…/pull.go• L78-191 pkg/…/load.go• L225-263

Remote execution

Remote execution lets a workflow inspect a node or run a collector in a pod without treating the remote environment as the local process. The workflow selects nodes, creates temporary Kubernetes resources, waits for them to produce results, reads logs or command output, and then removes the temporary resources.

This model supports two related uses:

  • A remote collector runs host checks on each selected node and combines the node results.
  • A run-pod or run-DaemonSet collector runs a user-specified workload and records its output.

Both uses keep execution bounded by a context or timeout. They also preserve useful failure output when a pod cannot start, an image cannot be pulled, or logs cannot be read.

References: pkg/…/remote_collector.go• L58-150 pkg/…/runner.go• L31-64 pkg/…/run_pod.go• L47-112 pkg/…/run_daemonset.go• L47-180

Kubernetes execution streams

Kubernetes execution streams carry commands, standard output, standard error, and copied files between a workflow and a pod. The shared executor prefers WebSocket transport and falls back to SPDY when the server or proxy does not support the first transport.

The same stream boundary supports command collectors and file collectors. A collector can therefore record text output or turn a tar stream into bundle files without changing how it reaches the pod.

References: pkg/…/exec.go• L11-26 pkg/…/exec.go• L117-163 pkg/…/copy.go• L93-179

External service access

External service access gives collectors one place to apply connection policy. HTTP calls use a shared client or transport, while database and registry calls can build TLS settings from direct values or Kubernetes Secrets.

The policy balances secure defaults with an explicit escape path. Certificate data is added to trusted roots when supplied. Client certificates are used for mutual TLS. Insecure verification is only enabled through a specific setting or an interactive retry path for an insecure upload connection.

References: pkg/…/config.go• L7-22 pkg/…/util.go• L160-213 pkg/…/aftercollection.go• L136-157

Registry access

Registry access checks whether named images are present and records each image result for later analysis. It can use credentials embedded in a specification, credentials from a Kubernetes image-pull Secret, or ambient local credentials.

The registry path distinguishes a missing image manifest from a missing repository or an unknown registry error. That distinction keeps a normal “image is absent” result separate from a connection or image-path failure.

References: pkg/…/registry.go• L28-35 pkg/…/registry.go• L60-106 pkg/…/registry.go• L117-188 pkg/…/registry.go• L191-219 pkg/…/registry.go• L320-343

Common service utilities

The Common runtime service utilities page describes shared HTTP, TLS, registry, path, and result helpers. These utilities matter when a workflow crosses from Kubernetes access into a remote endpoint or when it must preserve a useful result after a partial failure.

References: pkg/…/config.go• L7-22 pkg/…/util.go• L23-110 pkg/…/util.go• L160-253 pkg/…/registry.go• L117-188 pkg/…/interfaceutils.go• L11-54

Runtime safety

Runtime safety comes from combining least-privilege checks with bounded work and cleanup. A workflow checks the permissions needed for a collector or cluster scan, uses contexts and timeouts for calls and remote jobs, and removes temporary pods, DaemonSets, ConfigMaps, and managed image-pull Secrets after collection.

The runtime does not treat access as all-or-nothing. Cluster source loading can search a configured namespace or inspect namespaces one at a time when a cluster-wide read is forbidden. Remote collectors retain permission errors as part of the collection result so the final workflow can explain why data is missing.

References: internal/…/specs.go• L292-365 pkg/…/remote_collector.go• L333-377 pkg/…/runner.go• L45-52 pkg/…/run_daemonset.go• L78-91

Collected data protection

Collected data protection prevents credentials and other secret values from entering support bundles in clear text. The redaction service combines built-in rules with specification-defined rules that can target a file and replace matching values with a mask while preserving the surrounding content.

The service also records each redaction by file and redactor. Built-in coverage includes credential-like environment variable names, connection strings, selected Kubernetes custom-resource fields, and multiline JSON values. The redaction stream leaves binary data and line endings unchanged when no matching text is present.

References: pkg/…/redact.go• L38-62 pkg/…/redact.go• L105-150 pkg/…/redact.go• L153-231 pkg/…/redact.go• L234-250 pkg/…/redact.go• L500-530 pkg/…/single_line_test.go• L338-451 pkg/…/single_line_test.go• L559-650

Distribution recognition

Distribution recognition turns collected cluster evidence into a platform result for analysis. It uses node metadata and, when available, API resource groups to identify supported Kubernetes distributions before matching workflow outcomes.

The recognition path tolerates missing API-resource data because older bundles may not contain it. Tanzu can be identified from node labels alone or from its API group, while provider names are normalized so workflow conditions can use common spellings.

References: pkg/…/distribution.go• L76-98 pkg/…/distribution.go• L101-206 pkg/…/distribution.go• L209-316 pkg/…/distribution.go• L319-427 pkg/…/distribution_test.go• L293-361

The following diagram shows the shared runtime path from a workflow request to a bounded result.

flowchart TD
    A[Workflow request] --> B[Build Kubernetes access]
    B --> C{Choose source or target}
    C --> D[Load and resolve specifications]
    C --> E[Read cluster resources]
    C --> F[Run work on selected nodes]
    C --> G[Call HTTP or registry service]
    D --> H[Run collection or preflight]
    E --> H
    F --> H
    G --> H
    H --> I[Bounded result and diagnostics]
    I --> J[Cleanup temporary resources]

Change checklist

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

  • Changes to Kubernetes API registration must remain aligned across the scheme, generated client set, and every loader that decodes the affected kind.
  • Changes to Secret or ConfigMap value references must preserve namespace defaults, optional-reference behavior, and the requirement for a Kubernetes client.
  • Changes to v1beta3 support-bundle conversion must preserve both reference resolution and the shared support-bundle fields and collector behavior.
  • Changes to remote collector resources must preserve the create, wait, result, and cleanup sequence for both single-node and all-node execution.
  • Changes to registry credential handling must keep direct credentials, Kubernetes image-pull Secrets, and ambient credentials compatible with public and private images.
  • Changes to shared HTTP or TLS policy must be checked against specification downloads, support-bundle uploads, redaction reports, and remote service collectors.
  • Changes to transport selection for pod exec or file copy must preserve both WebSocket support and the SPDY fallback path.
  • Changes to built-in or configured redaction rules must preserve file matching, masked output, redaction records, and the protection of binary data and line endings.
  • Changes to distribution signals or outcome matching must preserve the optional API-resource path, provider-name normalization, and the precedence between overlapping provider signals.

Important failure modes

TriggerConsequenceGuard
A v1beta3 reference needs a Secret or ConfigMap but no Kubernetes client is availableThe support-bundle specification cannot loadRequire cluster access for referenced values and fail with a source error.
v1beta3 conversion resolves references but drops shared support-bundle fields or collectorsA valid specification loads with incomplete behaviorPreserve the shared converted specification and verify reference resolution separately.
The current identity cannot list or get cluster-wide Secrets and ConfigMapsCluster source discovery may miss specifications or stop at a broad scanCheck access first and fall back to namespace-scoped search or the kubeconfig namespace.
A remote collector cannot create, schedule, or read its temporary podNode data is incomplete or the remote collection failsUse node selection, wait limits, preserved error output, and cleanup.
A registry returns a missing repository instead of a missing manifestA valid image check can become a misleading “image absent” resultDistinguish repository errors from manifest-not-found responses.
A pod exec server or proxy rejects WebSocket upgradeCommand or file collection fails if no alternate transport is usedUse the shared WebSocket-first executor with SPDY fallback.
A remote endpoint has an untrusted certificateThe request fails unless the endpoint provides trusted certificate dataUse supplied CA or client certificate data, with insecure retry only through the explicit user path.
A new credential-bearing value does not match a built-in or configured redaction ruleSensitive data can remain in a support bundleAdd a path-aware redaction rule and verify the output and redaction record.
Collected node data is missing or malformedDistribution analysis cannot produce a reliable platform resultTreat node collection and decoding as required inputs and keep API-resource data optional.

Key files

FileWhy to read it
pkg/…/config.goShows how workflow commands turn Kubernetes flags into reusable cluster configuration.
pkg/…/auth.goShows the permission check used before broad Secret and ConfigMap access.
pkg/…/exec.goShows the shared transport boundary for pod command streams.
pkg/…/discovery.goShows how workflows test API resource support.
pkg/…/clientset.goShows access to the Troubleshoot API versions through one client set.
pkg/…/loader.goShows how raw YAML and Kubernetes objects become workflow specifications.
pkg/…/supportbundle_v1beta3_preservation_test.goConfirms that v1beta3 Secret and ConfigMap references resolve without changing shared support-bundle behavior.
internal/…/specs.goShows how CLI, cluster, HTTP, and OCI sources are combined.
pkg/…/resolver.goShows how Secret and ConfigMap references become values.
pkg/…/pull.goShows how published OCI specifications are selected and authenticated.
pkg/…/remote_collector.goShows the node selection and remote host collection lifecycle.
pkg/…/runner.goShows how temporary Kubernetes resources run host collectors and return logs.
pkg/…/registry.goShows registry presence checks and credential source handling.
pkg/…/util.goShows shared TLS, node, naming, and result helpers used by collectors.
pkg/…/config.goShows the shared HTTP transport used by external calls.
pkg/…/redact.goShows how collected output is masked and how redaction records are tracked.
pkg/…/distribution.goShows how collected cluster evidence is turned into distribution outcomes.