engine

package
v0.2.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const GapKBCoverage inventory.Capability = "kb-coverage"

GapKBCoverage is the CapabilityGap capability recorded when the target is beyond the knowledge base horizon. It is not a collector capability.

View Source
const GapTarget inventory.Capability = "target"

GapTarget is the CapabilityGap capability recorded when the target is not an upgrade of the cluster. It is not a collector capability.

View Source
const MaxFindingNamespaces = 100

MaxFindingNamespaces caps the namespaces a finding lists, in Namespaces (NamespacesOmitted counts the rest) and in an API usage finding's evidence sentence, as inventory.MaxObjectRefs caps its objects: a finding's size does not grow with how many namespaces it affects. Its Teams still come from every affected namespace.

View Source
const ReportSchemaVersion = 1

ReportSchemaVersion versions the JSON shape of a report: `scan --output json` (and --write-baseline) and the server's report-shaped /api/v1 responses. Within one schemaVersion fields are only ever added, never renamed, removed, retyped or given a new meaning, so consumers must ignore fields they do not know; any breaking change bumps it (see docs/compatibility-policy.md and api/report.schema.json).

Variables

View Source
var ErrReportTooLarge = errors.New("the report would be over its size limit")

ErrReportTooLarge is EvaluateWithin's error for an inventory whose report would be over its size limit.

Functions

func HopTargets added in v0.2.0

func HopTargets(k kb.KB, from, to inventory.Version) []inventory.Version

HopTargets is the minor the control plane reaches at each hop from from to to: from each version, the farthest k.UpgradeSteps step that does not pass to, else the next minor. Empty when to is not newer than from (or on another major, which Kubernetes has never released).

func PlanFrom added in v0.2.0

func PlanFrom(inv inventory.Inventory) (inventory.Version, bool)

PlanFrom is the minor a live cluster's plan starts from: its oldest kube-apiserver, the version Evaluate judges an upgrade from. ok is false in files mode or without a parseable version.

func Score

func Score(findings []Finding) (score int, ready bool)

Score implements the spec §6 formula:

score = 100 − min(75, 25·#blockers) − min(20, 5·#warnings)
ready = #blockers == 0

The caps bound the deductions, so the score never drops below 5. Info findings are listed but never scored. This ready is findings-only (per-team scores use it); a Report's readiness is its Verdict, which is also unknown when a required capability was not assessed.

func TeamScores

func TeamScores(r Report) map[string]TeamScore

TeamScores groups a report's findings by team and scores each subset with Score. A finding attributed to N teams counts for each of them; a finding with no teams is attributed to the empty-string team "" (callers render it as "unattributed"). Pure: no I/O, no clock — same contract as Evaluate. The result is deliberately NOT part of engine.Report; servers and CLIs compute it at presentation time.

Types

type BaselineState added in v0.2.0

type BaselineState string

BaselineState mirrors SARIF's result.baselineState values.

const (
	BaselineNew       BaselineState = "new"
	BaselineUnchanged BaselineState = "unchanged"
)

type CapabilityGap

type CapabilityGap struct {
	Capability inventory.Capability `json:"capability"`
	Reason     string               `json:"reason"`
	// Partial: the capability ran but did not read everything; Skipped is
	// what it named as unread (see inventory.CapabilityStatus).
	Partial  bool     `json:"partial,omitempty"`
	Skipped  []string `json:"skipped,omitempty"`
	Required bool     `json:"required,omitempty"`
}

CapabilityGap is one thing the evaluation could not assess. Capability is usually a collector capability whose sub-collector failed (Reason is its error). The engine also adds gaps of its own:

  • capability "versions", when the inventory's versions capability is available but the server version is missing or unparseable — the kubelet and control-plane skew rules then had no reference version;
  • capability "kb-coverage" (GapKBCoverage), when the target is newer than the knowledge base's MaxKnownK8s — removals in releases the KB does not know about cannot be found;
  • capability "target" (GapTarget), when a cluster inventory's oldest kube-apiserver already runs the target minor or a newer one — the target is not an upgrade, and every check judges a newer minor.

A capability that is available but Partial (it could not read all it covers) is a gap too, with Partial set and the capability's Skipped.

Required marks gaps that make the verdict unknown, because a blocker may be behind them:

  • api-usage, kb-coverage and target, always;
  • versions, for cluster inventories;
  • addons, for cluster inventories while the KB's add-on registry is not empty: the EOL add-on check is a headline check, and files mode has no running add-ons to detect;
  • a partial api-usage, when Skipped names an API the KB removes at or before the target (an unchecked object of it would be a blocker);
  • a partial versions, for cluster inventories, when Skipped names a component whose version upstream would have told but was not read (it may be the one past the skew policy).

Other gaps only narrow what the report covers: a partial api-usage that skipped only APIs removed later or never (their findings are warnings or info) or none the KB flags, a partial versions naming no component (a vendor kube-proxy image, OKE's), deprecated-calls (managed control planes commonly deny /metrics), helm (Secrets are commonly denied; live objects are still checked by api-usage, and add-ons by their images).

func (CapabilityGap) Label added in v0.2.0

func (g CapabilityGap) Label() string

Label names the gap as every output renders it: the capability, with "partial" and "required" in parentheses when they apply, e.g. "api-usage (partial, required)".

type Category

type Category string
const (
	CatRemovedAPI         Category = "removed-api"
	CatDeprecatedAPI      Category = "deprecated-api"
	CatDeprecatedAPIInUse Category = "deprecated-api-in-use"
	CatEOLAddon           Category = "eol-addon"
	CatEOLApproaching     Category = "eol-approaching"
	CatVersionSkew        Category = "version-skew"
	CatChartIncompat      Category = "chart-incompat"
	CatKBStale            Category = "kb-stale"
	// CatAddOnNoData (info): a detected add-on whose version has no
	// lifecycle data, so its EOL and compatibility were not assessed.
	CatAddOnNoData Category = "addon-no-data"
	// CatUnknownAPI (info): objects of a built-in API group (one the KB
	// has entries for, core included) at a version/kind the KB does not
	// know, so whether the target serves it was not assessed.
	CatUnknownAPI Category = "unknown-api"
	// CatCRDVersion: a CustomResourceDefinition version problem that
	// breaks an add-on upgrade, whatever the Kubernetes target: custom
	// resources at a version the CRD does not serve (blocker) or
	// deprecates (warning; info when none is in use), or a
	// status.storedVersions entry it no longer serves (warning).
	CatCRDVersion Category = "crd-version"
)

type Envelope added in v0.2.0

type Envelope struct {
	SchemaVersion int    `json:"schemaVersion"`
	ToolVersion   string `json:"toolVersion"`
}

Envelope leads every report-shaped JSON document: embedded first in the presentation struct, its fields come before the report's. ToolVersion is informational (the build that wrote the document) and carries no compatibility meaning.

func NewEnvelope added in v0.2.0

func NewEnvelope(toolVersion string) Envelope

NewEnvelope is the envelope of a report written by toolVersion.

type Finding

type Finding struct {
	Category Category `json:"category"`
	Severity Severity `json:"severity"`
	// Key is the finding's stable, count-free identity: it never embeds
	// object counts, node counts, or other volatile numbers, so the same
	// underlying problem keeps the same Key across snapshots even as Title
	// fluctuates ("3 objects" → "2 objects"). Notification delta diffing
	// keys on it. Convention: category + "/" + stable discriminator
	// (e.g. "removed-api/extensions/v1beta1/Ingress", "eol-addon/ingress-nginx").
	Key    string   `json:"key,omitempty"`
	Title  string   `json:"title"`           // one line, deterministic
	Detail string   `json:"detail"`          // evidence sentence(s), deterministic
	Teams  []string `json:"teams,omitempty"` // sorted, deduped; of every affected namespace, listed or not
	// Namespaces are the affected namespaces, sorted, at most
	// MaxFindingNamespaces; NamespacesOmitted counts the ones not listed.
	Namespaces        []string `json:"namespaces,omitempty"`
	NamespacesOmitted int      `json:"namespacesOmitted,omitempty"`
	Remediation       string   `json:"remediation,omitempty"`
	Citations         []string `json:"citations,omitempty"`
	// Objects identifies the affected objects for API-usage findings
	// (copied from inventory.APIUsage, so at most inventory.MaxObjectRefs),
	// sorted by file, line, namespace, name; ObjectsOmitted counts the
	// affected objects not listed. Empty when the collector could not
	// identify objects.
	Objects        []inventory.ObjectRef `json:"objects,omitempty"`
	ObjectsOmitted int                   `json:"objectsOmitted,omitempty"`
	// BaselineState is set only when the report was compared with a
	// baseline (scan --baseline): BaselineUnchanged when the baseline
	// already had this Key and every object listed here, else BaselineNew.
	// The CLI gate fails only on new findings; score and verdict count both.
	BaselineState BaselineState `json:"baselineState,omitempty"`
}

type FindingRef added in v0.2.0

type FindingRef struct {
	Key      string   `json:"key"`
	Severity Severity `json:"severity"`
	// Was is the severity at the last earlier hop that had the finding;
	// set only in Hop.Changed.
	Was   Severity `json:"was,omitempty"`
	Title string   `json:"title"`
	// Since is the To of the hop that lists the finding in full.
	Since inventory.Version `json:"since"`
}

FindingRef refers to a finding listed in full at an earlier hop, with its severity and title at this one.

type Hop added in v0.2.0

type Hop struct {
	From  inventory.Version `json:"from"`
	To    inventory.Version `json:"to"`
	Score int               `json:"score"` // Evaluate's at To
	// Verdict is Evaluate's at To: blocked when any finding of this hop,
	// new or referenced, is a blocker.
	Verdict  Verdict      `json:"verdict"`
	Findings []Finding    `json:"findings"` // first seen at this hop; Evaluate's order
	Changed  []FindingRef `json:"changed,omitempty"`
	Carried  []FindingRef `json:"carried,omitempty"`
	// NotAssessed is Evaluate's at To, every gap (not only new ones).
	NotAssessed []CapabilityGap `json:"notAssessed,omitempty"`
}

Hop is one control-plane upgrade of an upgrade plan (see Plan): the cluster as it is, judged at To. Findings lists only what this hop adds; a finding listed at an earlier hop is referenced instead, in Changed when its severity differs from the hop before, else in Carried. So each finding is listed in full once, at its first hop, and Findings, Changed and Carried together are everything the cluster has to fix before the control plane reaches To.

func Plan added in v0.2.0

func Plan(inv inventory.Inventory, k kb.KB, from, to inventory.Version, now time.Time) []Hop

Plan judges the cluster at each hop from from to to (HopTargets) and returns the hops in order, each finding listed at its first hop only (see Hop). It is empty when to is not an upgrade of from. Like Evaluate it is pure: the final hop's blockers, score and verdict are Evaluate's at to.

func PlanReports added in v0.2.0

func PlanReports(from inventory.Version, reports []Report) []Hop

PlanReports builds the hops of a plan from from out of the reports judged at each hop's target, in order (Plan evaluates them; the scan command passes them through its ignore rules first). A finding is identified by its Key.

func (Hop) Count added in v0.2.0

func (h Hop) Count(sev Severity) int

Count is the number of this hop's findings, new or referenced, at sev.

type Report

type Report struct {
	ClusterID string            `json:"clusterId"`
	Target    inventory.Version `json:"target"`
	// ServerVersion is the inventory's raw kube-apiserver GitVersion, the
	// version the target was judged against; empty in files mode.
	ServerVersion string `json:"serverVersion,omitempty"`
	// KubeContext and APIServer say which cluster a live scan read: the
	// kubeconfig context and the API server URL (scheme, host and port;
	// no credentials, path or query). Evaluate never sets them; the scan
	// command does. Empty in files mode.
	KubeContext string `json:"kubeContext,omitempty"`
	APIServer   string `json:"apiServer,omitempty"`
	KBVersion   string `json:"kbVersion"`
	Score       int    `json:"score"` // from findings only; see Score
	// Ready is Verdict == VerdictReady, kept for v0.1 consumers.
	Ready       bool            `json:"ready"`
	Verdict     Verdict         `json:"verdict"`
	Findings    []Finding       `json:"findings"`              // sorted: severity desc, category, title
	NotAssessed []CapabilityGap `json:"notAssessed,omitempty"` // sorted by capability
	// Suppressed lists what ignore rules took out of Findings (see
	// internal/suppress); Evaluate never sets it.
	Suppressed []SuppressedFinding `json:"suppressed,omitempty"`
	// UnrecognizedImages are the image repositories no registry image
	// matcher claims (inventory.UnrecognizedImages), so an add-on
	// detection gap is visible; never findings, so they change neither
	// score nor verdict. Sorted, deduplicated, at most
	// inventory.MaxUnrecognizedImages; UnrecognizedImagesOmitted counts
	// the ones the cap dropped.
	UnrecognizedImages        []string `json:"unrecognizedImages,omitempty"`
	UnrecognizedImagesOmitted int      `json:"unrecognizedImagesOmitted,omitempty"`
	// Hops is the upgrade plan up to Target (see Plan), set by scan
	// --plan; Evaluate never sets it. The rest of the report is the
	// final target's.
	Hops []Hop `json:"hops,omitempty"`
}

func Evaluate

func Evaluate(inv inventory.Inventory, k kb.KB, target inventory.Version, now time.Time) Report

Evaluate is the pure evaluation entrypoint: no I/O, no clock reads — now is injected for EOL-window math. Output is fully deterministic for a given (inventory, kb, target, now), whatever the order of the inventory's slices. EvaluateWithin bounds its size.

func EvaluateWithin added in v0.2.0

func EvaluateWithin(inv inventory.Inventory, k kb.KB, target inventory.Version, now time.Time, maxBytes int) (Report, error)

EvaluateWithin is Evaluate for a report of at most maxBytes: it charges each finding it builds, and what the report adds besides, at about the bytes its strings take (findingSize), and stops with ErrReportTooLarge as soon as the charge passes maxBytes. Its findings are built one input element at a time, so an evaluation that stops holds at most maxBytes of report and the findings of one element. Within the limit the report is Evaluate's.

A server evaluates inventories anyone with a push token sends: the engine repeats what an inventory names (a team in every finding of its namespaces, a release in the text of each of its findings), so a few megabytes of a push could build a report many times its size.

func (*Report) Rescore added in v0.2.0

func (r *Report) Rescore()

Rescore recomputes Score, Verdict and Ready from Findings and NotAssessed, for callers that remove findings after Evaluate.

type Severity

type Severity string
const (
	SevBlocker Severity = "blocker"
	SevWarning Severity = "warning"
	SevInfo    Severity = "info"
)

type SuppressedFinding added in v0.2.0

type SuppressedFinding struct {
	Finding
	Reason string `json:"reason"`
	// Source names what suppressed it: the config file, "annotation", or
	// "spec.ignore" (the agent).
	Source  string `json:"source"`
	Expires string `json:"expires,omitempty"` // YYYY-MM-DD, as the rule gave it
}

SuppressedFinding is a finding, or some of its objects (Objects then lists only those), that an ignore rule or object annotation accepted. It is excluded from score and verdict but still reported, with why.

type TeamScore

type TeamScore struct {
	Score    int  `json:"score"`
	Ready    bool `json:"ready"`
	Blockers int  `json:"blockers"`
	Warnings int  `json:"warnings"`
}

TeamScore is one team's slice of a report, scored with the same spec §6 formula as the cluster score, over only that team's findings.

type Verdict added in v0.2.0

type Verdict string

Verdict is the report's readiness answer.

const (
	// VerdictReady: no blockers, and everything required was assessed.
	VerdictReady Verdict = "ready"
	// VerdictBlocked: at least one blocker finding.
	VerdictBlocked Verdict = "blocked"
	// VerdictUnknown: no blockers found, but a required gap (see
	// CapabilityGap.Required) means blockers may have been missed.
	VerdictUnknown Verdict = "unknown"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL