Documentation
¶
Index ¶
- Constants
- func AddGatherFlags(fs *pflag.FlagSet, opts *Options)
- func DefaultArtifactDir(now time.Time) string
- func PlannedArtifacts() []string
- func Run(opts *Options, f Clients, progress Progress) error
- type Clients
- type Collector
- type CollectorStatus
- type CopyOptions
- type Error
- type FileEntry
- type Gatherer
- type Manifest
- type ManifestFlags
- type Options
- type PodCommandRunner
- type PodFileFetcher
- type PodInfo
- type Progress
- type RunFunc
- type TarPipe
Constants ¶
const BundleSchemaVersion = "1"
BundleSchemaVersion is the version of the manifest's own shape. A reader checks it before trusting any other field, and it moves when a field changes meaning rather than when a collector is added.
const DefaultExecTimeout = 2 * time.Minute
DefaultExecTimeout bounds one exec or one copy out of a driver pod. A bug report takes tens of seconds on a busy node, so this is generous; what it rules out is a pod that accepted the connection and will never answer, which without a deadline costs the user the whole bundle rather than one file.
const ManifestFileName = "manifest.json"
ManifestFileName is the index of a bundle. It is written last, so that it can hash everything else.
const StatusOK = "ok"
StatusOK is the manifest status of a collector that ran and wrote what it planned to. The other two forms are "skipped:<reason>" and "error:<text>", built by the gather as it runs.
Variables ¶
This section is empty.
Functions ¶
func AddGatherFlags ¶ added in v0.2.0
AddGatherFlags registers the flags that belong to a gather itself on fs, writing into opts.
It lives here rather than in a command package because more than one command runs this gather: kubectl nv adm must-gather over a cluster and kubectl nv debug over one node. A support engineer who learned one command must not find the other spelling the same flag differently.
kubectl nv debug registers its flags from here. kubectl nv adm must-gather still has a copy of its own, so this is not yet the single registration it is meant to be; moving that command onto this function is what makes the drift impossible rather than merely tested for.
--node is deliberately not among them. must-gather takes it as a flag and debug takes the node as its argument, and a command that offered both would let the two disagree about which node the bundle is of.
func DefaultArtifactDir ¶ added in v0.2.0
DefaultArtifactDir names the directory a gather writes to when the user did not choose one. It carries the gpu-operator script's prefix, so a bundle collected by either tool is recognisable by name.
The script's name is minute-resolution. Two gathers started in the same minute, which is what a support engineer does when the first one came out wrong, then land in the same directory and the second run's bundle holds the first run's files wherever a collector was skipped this time. The seconds and the suffix make each run its own.
func PlannedArtifacts ¶ added in v0.2.0
func PlannedArtifacts() []string
PlannedArtifacts is every artifact name a bundle can hold, with the placeholders left in. It needs no cluster, which is what lets the parity check against the gpu-operator script run as a unit test.
Types ¶
type Clients ¶
type Clients interface {
KubernetesClient() (kubernetes.Interface, error)
DynamicClient() (dynamic.Interface, error)
RESTConfig() (*rest.Config, error)
}
Clients hands the gatherer the clients it works through. The command layer has a factory that satisfies this; a test supplies fakes. It is declared here, where it is used, so that the gatherer stays a library the commands call rather than one that calls back into them.
type Collector ¶ added in v0.2.0
type Collector struct {
// Name is what the manifest records this collector as, and what the user
// sees when it is skipped.
Name string
// Step is the progress line, printed before the collector runs.
Step string
// Artifacts are the files this collector writes, with a placeholder where
// the cluster supplies part of the name.
Artifacts []string
// Run collects. It returns errSkipped when there was nothing to do, any
// other error when the gather cannot carry on.
Run func(g *Gatherer, s *gatherState) error
}
Collector is one unit of a gather: a name the manifest records it under, the artifacts it plans to write, and the work itself.
The artifacts are declared rather than discovered so that the set a gather would produce can be computed without a cluster, which is what the parity check against the gpu-operator script is made of.
func Collectors ¶ added in v0.2.0
func Collectors() []Collector
Collectors is the registry, in the order a gather runs it.
The order is the gpu-operator script's (lines 92 to 170 at f6d32bad44ee) and the base's: the cluster's own resources, then the node survey, then the namespace-scoped work. It is load bearing. The ClusterPolicy is the first file support asks for, and a cluster whose feature discovery has not labelled a node yet is exactly the cluster someone runs a must-gather on, so the node survey must not run in front of it.
type CollectorStatus ¶ added in v0.2.0
type CollectorStatus struct {
// Name is the collector's name in the registry.
Name string `json:"name" yaml:"name"`
// Status is "ok", "skipped:<reason>" or "error:<text>".
Status string `json:"status" yaml:"status"`
// Artifacts are the files this collector wrote, by name.
Artifacts []string `json:"artifacts" yaml:"artifacts"`
}
CollectorStatus is what one collector did.
type CopyOptions ¶
type CopyOptions struct {
Container string
Namespace string
NoPreserve bool
MaxTries int
ClientConfig *restclient.Config
Clientset kubernetes.Interface
ExecParentCmdName string
genericiooptions.IOStreams
}
CopyOptions have the data required to perform the copy operation
func NewCopyOptions ¶
func NewCopyOptions(ioStreams genericiooptions.IOStreams) *CopyOptions
NewCopyOptions creates the options for copy
type Error ¶
type Error struct {
// Err is what went wrong.
Err error
// Partial reports that at least one artifact was collected before the
// failure, so the bundle holds part of what was asked for.
Partial bool
}
Error says how far a gather got before it failed, which is what decides whether the bundle it left behind is worth sending.
type FileEntry ¶ added in v0.2.0
type FileEntry struct {
// Path is the file's name within the bundle.
Path string `json:"path" yaml:"path"`
// Size is its length in bytes.
Size int64 `json:"size" yaml:"size"`
// SHA256 is its digest, hex encoded.
SHA256 string `json:"sha256" yaml:"sha256"`
}
FileEntry is one file of the bundle, with what it should hash to.
type Gatherer ¶
type Gatherer struct {
// contains filtered or unexported fields
}
Gatherer holds all the initialized resources needed for must-gather operations.
func NewGatherer ¶
NewGatherer initializes a new Gatherer by performing the following tasks: 1. Create the artifact directory. 2. Create log files for stdout and stderr. 3. Take the clients from the factory. If any step fails, any opened file resources are closed before returning.
type Manifest ¶ added in v0.2.0
type Manifest struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
// BundleSchemaVersion is the version of this document's shape.
BundleSchemaVersion string `json:"bundleSchemaVersion" yaml:"bundleSchemaVersion"`
// ToolVersion is the kubectl-nv that collected the bundle.
ToolVersion string `json:"toolVersion" yaml:"toolVersion"`
// Context is the kubeconfig context the bundle was collected through.
Context string `json:"context" yaml:"context"`
// Timestamp is when the bundle was written, in UTC.
Timestamp string `json:"timestamp" yaml:"timestamp"`
// Flags records what was asked of the gather, so that a bundle missing a
// node's evidence can be read as narrowed rather than as incomplete.
Flags ManifestFlags `json:"flags" yaml:"flags"`
// Collectors is one entry per collector of the registry, in the order they
// ran.
Collectors []CollectorStatus `json:"collectors" yaml:"collectors"`
// Files is every file of the bundle except this one.
Files []FileEntry `json:"files" yaml:"files"`
}
Manifest is the index of a must-gather bundle: what produced it, what was asked of it, which collectors ran, and what every file in it hashes to.
A bundle travels to NVIDIA support as an archive. Without this, a file that arrived truncated and a collector that was never allowed to run look the same from the outside: a file that is not there.
type ManifestFlags ¶ added in v0.2.0
type ManifestFlags struct {
// Node is the --node the gather was narrowed to, empty for the whole
// cluster.
Node string `json:"node" yaml:"node"`
// Since is the --since log window, empty for the whole log.
Since string `json:"since" yaml:"since"`
// NoExec reports whether --no-exec kept the gather out of the driver pods.
NoExec bool `json:"noExec" yaml:"noExec"`
}
ManifestFlags is what the user asked of the gather.
type Options ¶
type Options struct {
ArtifactDir string // Directory to store gathered artifacts/logs.
Debug bool // Name every artifact as it is written.
// Node narrows the whole gather to one node: its node object, the operand
// pods on it, their logs, its bug report and its device usage. The
// cluster-scoped objects are collected whatever it says, because they are
// what the node's state has to be read against.
Node string
// Since bounds the window of the current container logs. Zero means the
// whole log.
Since time.Duration
// NoExec keeps the gather out of the driver pods: no bug report and no
// device usage, and the manifest records both as skipped by flag.
NoExec bool
// ExecTimeout bounds one exec or one copy out of a driver pod. Zero means
// DefaultExecTimeout. A pod that accepted the connection and never answers
// costs one file rather than the whole bundle.
ExecTimeout time.Duration
// ToolVersion is the kubectl-nv version the manifest records the bundle as
// having been collected by.
ToolVersion string
// Context is the kubeconfig context the bundle was collected through, for
// the manifest. A bundle that does not say which cluster it came from is a
// bundle that gets filed against the wrong one.
Context string
// FetchPodFile replaces the live exec-and-copy that pulls a bug report out
// of a driver pod. It is the seam the tests drive the gatherer through
// without a cluster to exec into; a nil value means the live one.
FetchPodFile PodFileFetcher
// RunInPod replaces the live exec used by the device usage collector.
RunInPod PodCommandRunner
}
Options defines the configurable parameters for the must-gather operation.
func (*Options) ValidateWindows ¶ added in v0.2.0
ValidateWindows rejects a duration the gather cannot do anything useful with. It is a usage error, which exits 2: the user can fix it by typing something else.
type PodCommandRunner ¶ added in v0.2.0
type PodCommandRunner func(ctx context.Context, pod *v1.Pod, container, command string) (string, error)
PodCommandRunner runs command in one container of pod and returns its standard output. It stops when ctx is done.
type PodFileFetcher ¶
PodFileFetcher runs the bug-report command inside pod and copies the resulting file out of the pod to destPath on the local filesystem. It stops when ctx is done, which is how a pod that never answers costs one artifact rather than the gather.
type Progress ¶
type Progress interface {
Infof(format string, a ...any)
Warnf(format string, a ...any)
Errorf(format string, a ...any)
}
Progress is where a gather says what it is doing. It is the subset of output.Logger the gatherer needs, declared here so that this package does not depend on how the commands choose to print.