Documentation
¶
Overview ¶
Package suppress applies accepted findings to an engine report: ignore rules (from .upgradescope.yaml or ClusterReadiness spec.ignore) and the ignore object annotation (apigroup.IgnoreAnnotation) move findings, or single objects of a finding, into Report.Suppressed with the reason given, so they stop counting toward score and verdict but stay visible. It also compares a report with a baseline report (see Baseline).
Index ¶
Constants ¶
const AnnotationSource = "annotation"
AnnotationSource is SuppressedFinding.Source for annotation suppressions.
const ConfigFile = ".upgradescope.yaml"
ConfigFile is the config file name scan discovers (see FindConfig).
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply returns r with the findings, or listed objects of findings, that rules or object annotations accept moved to Suppressed, and score and verdict recomputed; r itself is not modified, and is returned unchanged when nothing matches. Per finding, rules apply in order and then annotations; the first to match an object takes it.
A rule without object selectors takes the whole finding (unlisted objects included). With selectors it takes the listed objects that match all of them; a finding with no listed objects (add-ons, skew) matches only a namespace selector, and only when every namespace it names matches. A finding all of whose objects are taken, none omitted, leaves Findings; otherwise it stays, with the remaining objects and a note.
The deprecated-API callers folded into an API usage finding (Finding.Callers) are evidence about clients, not about its objects: only a rule without object selectors that takes the finding takes them too. When object selectors or annotations take every object, each caller stands as the deprecated-api-in-use finding it is on its own (engine.Caller.Finding), at its own severity, and is matched against the rules like any finding, so a rule for its key or category, without selectors, still suppresses it. Fail closed: the client calling the removed API may not be the one that wrote the suppressed objects.
The returned warnings name expired rules (which do not apply), invalid rules (skipped), and annotations without a reason (not applied), in that order. Between the rule and the annotation warnings comes one warning for all the objects on the deprecated pre-v0.2.0 annotation keys that annotate a finding of r (see apigroup.LegacyIgnoreWarning), however many there are: a consumer that keeps only the first few warnings still keeps it.
func FindConfig ¶
FindConfig returns the config file scan uses when none is named: the one in scanRoot, else the one at the root of the git repository holding scanRoot (the nearest directory upwards with a .git entry), else "".
Types ¶
type Baseline ¶
type Baseline struct {
// contains filtered or unexported fields
}
Baseline is what a previous JSON report found, for gating only on what is new since. Findings are matched by Key, which is count-free and stable across runs (engine.Finding.Key), and by severity, because a key can escalate (an API removed one minor past the target is a warning; at the target, the same key is a blocker); objects by namespace, name and file, not line, so editing around an object does not make it new.
func ReadBaseline ¶
ReadBaseline parses a JSON report (scan --output json, or --write-baseline) whose schemaVersion is at most schemaVersion. Only its findings count: suppressed entries are not baseline, so a finding whose rule expires is new again.
type Config ¶
type Config struct {
Ignore []Rule `yaml:"ignore"`
}
Config is the .upgradescope.yaml document.
func LoadConfig ¶
LoadConfig reads and validates a config file. Unknown fields and invalid rules are errors naming the file.
type Options ¶
type Options struct {
Now time.Time // decides which rules have expired
// Source labels rule suppressions and prefixes warnings: the config
// file path, or "ClusterReadiness spec.ignore".
Source string
// FileBase is joined before object file paths when matching file
// globs: the scanned root relative to the config file's directory, so
// globs are written relative to the config file.
FileBase string
}
Options parameterize Apply.
type Rule ¶
type Rule struct {
Key string `json:"key,omitempty" yaml:"key,omitempty"`
Category string `json:"category,omitempty" yaml:"category,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
File string `json:"file,omitempty" yaml:"file,omitempty"`
Reason string `json:"reason" yaml:"reason"`
Expires string `json:"expires,omitempty" yaml:"expires,omitempty"`
}
Rule is one ignore entry. It names findings by Key (exact) or Category, optionally narrowed to objects by Namespace, Name and File globs; Reason is required and Expires (YYYY-MM-DD, inclusive, UTC) optional. The same schema is ClusterReadiness spec.ignore.