Documentation
¶
Overview ¶
Package bundle writes and verifies the result bundle ADR-090 defines: a directory holding a certification's report, its per-component result rows as plain NDJSON, an account of anything that was lost, and a manifest that certifies the rest by digest.
The bundle exists so a consumer never has to walk NVCRE's object graph. The rows live in ConfigMap binaryData as gzipped NDJSON, sharded to stay under the API server's object limit, and none of that is a shape anyone outside the cluster should have to know. nvcrectl does the shard walk and the gunzip (ADR-090 decision 4), so what lands on disk is a directory of files.
The package is deliberately separate from pkg/report. pkg/report builds and renders the certification report; this assembles a verifiable artifact around it, and needs a Kubernetes client to do so, which pkg/report does not have and should not acquire.
Index ¶
- Constants
- Variables
- func ComponentFileNamesUnique(comps []ResolvedComponent) error
- func ValidateExportPaths(dir string, paths ...ExportPath) error
- func Write(dir string, c Contents) error
- type ComponentSet
- type Contents
- type ExportPath
- type FileEntry
- type Manifest
- type ResolvedComponent
- type ShardMismatchError
- type TruncationRecord
Constants ¶
const ( ManifestName = "manifest.json" ResultsName = "results.json" TruncationName = "truncation.json" ComponentsDir = "components" SchemaDir = "schema" )
File names and directories in a bundle. The layout is ADR-090 decision 4.
const FormatVersion = 1
FormatVersion is the bundle layout's version. A reader that does not recognise it must refuse the bundle rather than guess at the layout.
Variables ¶
var ErrNoManifest = errors.New("no " + ManifestName + " in bundle")
ErrNoManifest is returned when a directory holds no manifest.
Its own error so a caller can tell "this is not a bundle" from "this bundle is corrupt", which are different things to report to a user, without either becoming a reason to read the directory anyway.
Functions ¶
func ComponentFileNamesUnique ¶
func ComponentFileNamesUnique(comps []ResolvedComponent) error
ComponentFileNamesUnique reports a collision between two categories' file names, which would silently overwrite one with the other.
Two categories CAN name the same domain and variant and differ only in their options, which is what categoryOptionsSuffix exists for, so the file name carries the Workflow name as well. An earlier version of this comment claimed the collision was impossible; it was reachable by the headline use of that suffix, two compute/cutlass-gemm categories with different floors, and it refused the whole bundle rather than one category.
This check stays as the backstop. Domain and variant cannot contain a path separator because both are catalog directory names, and the Workflow name is a DNS-1035 label, so a collision now means two genuinely identical categories; that is loud here rather than a bundle quietly missing one.
func ValidateExportPaths ¶
func ValidateExportPaths(dir string, paths ...ExportPath) error
ValidateExportPaths refuses an export path that resolves inside dir.
A bundle lists every file it contains in manifest.json and a reader refuses one that holds anything unlisted, so the other export paths have to stay outside it. Both ways of getting this wrong were silent in different ways: a path written BEFORE the bundle became an unlisted file and the bundle's own self-verify failed after everything had been written and sealed, and one written AFTER left the bundle verifying clean, the command printing success, and the artifact on disk already invalid.
Checked up front rather than fixed by reordering the writes, because reordering only moves which of the two breaks.
Types ¶
type ComponentSet ¶
type ComponentSet struct {
// Scope names the run the rows came from, a Certification or a
// WorkloadRun.
Scope string `json:"scope,omitempty"`
Domain string `json:"domain"`
Variant string `json:"variant"`
// Path is the component rows file, relative to the bundle root.
Path string `json:"path"`
// ShardCount and RowCount are what the walk resolved, which equals what
// the Workflow sealed or the bundle is not written at all.
ShardCount int32 `json:"shardCount"`
RowCount int64 `json:"rowCount"`
// Final reports whether the run had finished producing when this was read.
// A bundle built from a non-final total is a snapshot of a running job,
// which is legitimate and must not be mistaken for a complete one.
Final bool `json:"final"`
// TruncatedRowCount is how many rows were lost before they reached a
// shard. Non-zero means truncation.json has the detail.
TruncatedRowCount int64 `json:"truncatedRowCount,omitempty"`
}
ComponentSet is one category's resolved result set.
type Contents ¶
type Contents struct {
// Reports is the certification report, written as results.json in the same
// shape --results-file produces, so a consumer reading one can read the
// other.
Reports []*report.CertReport
// Components holds each category's resolved rows, in the order the
// component files should be listed.
Components []ResolvedComponent
// Truncations is everything that was lost, from any category. Written even
// when empty, so a consumer can tell "nothing was lost" from "this bundle
// predates truncation reporting".
Truncations []TruncationRecord
}
Contents is everything that goes into a bundle.
type ExportPath ¶
ExportPath is one of a command's other output paths, named by its flag so a refusal can say which one is in the way.
type FileEntry ¶
type FileEntry struct {
Path string `json:"path"`
SHA256 string `json:"sha256"`
Bytes int64 `json:"bytes"`
}
FileEntry is one file's identity in the manifest.
type Manifest ¶
type Manifest struct {
FormatVersion int `json:"formatVersion"`
// FileCount is the number of entries in Files. Stored rather than derived
// so a truncated manifest that still parses is caught: a reader compares
// it against both len(Files) and what is on disk.
FileCount int `json:"fileCount"`
// Files lists every file in the bundle except the manifest itself, sorted
// by path so the manifest is byte-identical for identical content.
Files []FileEntry `json:"files"`
// Components records what the shard walk resolved, per category.
//
// The manifest is only written when the resolved counts match the sealed
// ones, so its existence already asserts completeness. These numbers make
// that assertion auditable instead of implicit.
Components []ComponentSet `json:"components,omitempty"`
}
Manifest is the bundle's index, written last.
Written last on purpose, and it is the whole integrity story. A bundle without a manifest is an incomplete write, and the reader refuses it rather than falling back to a directory glob (ADR-090: "a missing manifest means refuse the bundle, with no directory-glob fallback"). So the manifest's presence is the claim that the write finished, and its digests are the claim that nothing has changed since.
func Verify ¶
Verify checks a bundle against its manifest and returns the manifest.
Three rules, all normative in ADR-090, and each catches something the others cannot:
A missing manifest means refuse the bundle, with no directory-glob fallback. The manifest is written last, so its absence means the write did not finish; globbing the directory instead would read a partial bundle and report success.
A manifest that fails to parse, or whose file count does not match what is on disk, is a hard error rather than a degraded read. Both directions are checked: a file the manifest does not list is as much a disagreement as one it lists that is absent.
Every file the manifest lists is hashed, and a digest mismatch refuses the bundle. This is what the sha256 is for. A file count and a row count both survive a file being edited in place, so a bundle that passed only those checks would be certified as whole on evidence that cannot detect the one thing the digest exists to catch.
type ResolvedComponent ¶
type ResolvedComponent struct {
// Scope is the name of the run the rows came from: a Certification or a
// WorkloadRun. Part of the file name because `nvcrectl certification
// report` accepts several names at once, and two certifications that ran
// the same category would otherwise write the same component file and one
// would silently replace the other.
Scope string
Domain string
Variant string
// Workflow is the name of the Workflow the category ran as, when it had
// one. It is what makes the file name unique.
//
// Domain and variant do not: two categories can name the same pair and
// differ only in their options, which is the case categoryOptionsSuffix
// exists for, and that is not a hypothetical. Two compute/cutlass-gemm
// categories with different floors are the headline use of the suffix, and
// under a name built from domain and variant alone they collide,
// ComponentFileNamesUnique refuses the bundle, and the run's entire
// per-component evidence becomes unobtainable. The Workflow name already
// carries the suffix, so it distinguishes exactly the categories that are
// distinguishable.
Workflow string
NDJSON []byte
ShardCount int32
RowCount int64
Final bool
TruncatedRowCount int64
// Truncations is what the category's Jobs recorded as lost.
Truncations []TruncationRecord
}
ResolvedComponent is one category's rows, gunzipped and concatenated.
func ResolveCertification ¶
func ResolveCertification( ctx context.Context, c client.Client, cert *nvcrev1alpha1.Certification, ) ([]ResolvedComponent, error)
ResolveCertification walks every category's shards and returns them ready to write.
Each category is one Workflow, so each carries its own selector and its own sealed counts, mirrored onto the Certification status. A category that produced no component results is skipped rather than written as an empty file: an absent category and one that produced nothing are the same thing to a consumer, and a file of zero rows invites the reading that rows were expected and lost.
The namespace is resolved per category, not once for the Certification. WorkflowStatus.Namespace is where that Workflow's Jobs and their shards actually live, and the controller auto-generates it when the spec leaves it unset, so two categories of one Certification can sit in two namespaces. Listing one namespace for all of them would find no shards for the rest and fail the run as a sealed-count mismatch, which is the correct outcome for a genuinely missing shard and a misleading one for a bundle looking in the wrong place.
func ResolveWorkflow ¶
func ResolveWorkflow( ctx context.Context, c client.Client, scope string, wf *nvcrev1alpha1.Workflow, ) (ResolvedComponent, bool, error)
ResolveWorkflow walks one Workflow's shards, for the workloadrun path where there is no Certification above it.
Reports false when the Workflow sealed no component results, which every WorkloadRun in the repository does today. The caller writes no component file in that case rather than an empty one: a file of zero rows invites the reading that rows were expected and lost.
func (ResolvedComponent) FileName ¶
func (c ResolvedComponent) FileName() string
FileName is the component file's name within the components directory.
Built from whichever of scope, domain, variant and Workflow name are set, so a certification category reads as "<cert>-<domain>-<variant>-<workflow>.ndjson" and a WorkloadRun, which has no catalog category at all, reads as "<run>.ndjson" rather than carrying empty segments.
The Workflow name is what carries uniqueness; domain and variant are kept ahead of it because they are what a human scans the directory for, and the Workflow name alone reads as an opaque token.
type ShardMismatchError ¶
type ShardMismatchError struct {
Domain, Variant string
SealedShards, GotShards int32
SealedRows, GotRows int64
}
ShardMismatchError reports that the shards found do not match what was sealed. It is deliberately a hard failure: the bundle is not written.
This is where ADR-090 is explicit that FailedNodesFromRef's pattern must not be copied. That helper returns nil on a Get error, on a decode error and on a nil reference alike, so an unreadable ConfigMap is indistinguishable from nothing-to-report. For a node list that is a tolerable degradation. For the primary evidence of a certification it is not: a bundle short of its rows would carry a manifest certifying it as whole.
func (*ShardMismatchError) Error ¶
func (e *ShardMismatchError) Error() string
type TruncationRecord ¶
type TruncationRecord struct {
Scope string `json:"scope,omitempty"`
Domain string `json:"domain"`
Variant string `json:"variant"`
Reason string `json:"reason"`
Count int64 `json:"count"`
Node string `json:"node,omitempty"`
ComponentID string `json:"componentID,omitempty"`
Index int32 `json:"index,omitempty"`
Message string `json:"message,omitempty"`
}
TruncationRecord is one loss, as truncation.json carries it.
ADR-090 requires that rows lost to log pagination are "recorded as a partial read in truncation.json and are never collapsed to zero rows". The same file carries every other loss the write path recorded, because a consumer asking "is this evidence complete" wants one answer, not one per mechanism.
func CollectTruncations ¶
func CollectTruncations(comps []ResolvedComponent) []TruncationRecord
CollectTruncations flattens every category's truncation records, for the single truncation.json the bundle carries.