Documentation
¶
Overview ¶
Package inventory reads the installed component inventory from a live cluster and returns it as the component-to-version table an upgrade comparison consumes. It is the input side of `aicr upgrade-check --from cluster`, whose other half is the at-risk scan, an advisory pass over live resources that reports what an upgrade might disturb.
Read is the entry point for the version table. It builds both clients from one resolved kubeconfig, since a second authentication path could land on a different context and an inventory assembled from two clusters is a confident wrong answer, then reads the one source the named deployer writes. Helm's release records for helm, helmfile, terraform, flux and fleet: one paged List per storage driver, reduced to the newest revision of each release, decoded from the stored payload. Argo CD's Applications for argocd and argocd-helm: one paged List of the CRD. Both project onto one shape.
A component the read places but cannot version is kept in the table with no version, never dropped: an absent component reads as newly installed, which drops its transition and fails nothing. That covers a record that cannot be read, a release held by both storage drivers, and a loosely matched Application deploying outside the component's namespaces.
ReadReleases reads the same source with the same naming but stops before the version table. It returns every record attributed to each component, plus the AICR-stamped Helm records that match none, for a caller that acts on the records themselves, such as one removing what AICR installed.
ScanAtRisk is the other half, and it answers a different question about the same cluster. See "The at-risk scan" below.
What it answers for ¶
Both readers list cluster-wide and are given a scope: the set of component names the caller is comparing. Scope is decided per record, from the name, before anything about that record is validated.
This is what keeps a cluster's unrelated workloads out of the answer, and it is a correctness property rather than a performance one. Strict validation is owed to records that map to a component being reported on, because there a record that goes missing reads as a component being installed for the first time. It is not owed to the rest of the cluster: another team's Argo Application with no destination namespace, or a Helm record written in a storage format this build cannot read, are well-formed for their own purposes, and failing an upgrade check on them would be this package's bug. The rule is that a record which cannot affect the comparison cannot fail it either.
A component's name is not the name the cluster stores it under. Only helm, helmfile and terraform install under the component's own name; Flux composes "<targetNamespace>-<name>", Argo CD prepends a user-settable prefix, and the bundle writer's injected folders append a phase. So matching is loose, and what a record's tier buys is not inclusion but strictness:
- Confident, a name this project itself writes. Every check is strict and a malformed record fails the run, because it names a component being reported on and reading it wrong is worse than not running.
- Possible, a name some deployer's naming could have produced from a component's. A record that cannot be read is skipped and counted rather than fatal, because it is as likely to be a foreign workload sharing a token as a component's own, and this package cannot tell which.
- Out of scope, skipped before anything about it is examined.
Tying strictness to the tier is what makes the loose tier safe: widening the match can no longer make a run fail, only draw in a foreign record that reads perfectly well, which the comparison can still reject. Under-matching has no such safety valve, since a component whose record is never seen reports as newly installed.
Each reader accounts for itself separately in the result, and the two sets of counts are never summed: their units differ, since the Helm reader counts storage records and one release contributes one per retained revision, while the Argo reader counts Applications, of which a component has one. A scope naming no components is refused rather than answered, because an empty inventory is indistinguishable from a cluster with nothing installed and reads as every component being new.
From records to a version table ¶
Scope decides what is worth reading. Attribution decides what a record actually is, and it is the stricter question: the caller names the deployer, because the cluster does not record it and the transform is not invertible. A release called gpu-operator-gpu-operator is flux's gpu-operator installed into namespace gpu-operator, or helm's component of that literal name, and nothing on the record tells them apart.
Each deployer's rule inverts what that deployer writes: the component's own name for helm, helmfile, terraform and fleet, "<namespace>-<name>" for flux, and for Argo CD a raw suffix — its namePrefix is user-settable and need not end in a separator, so it cannot be enumerated — anchored by requiring the Application's destination namespace to be the component's. An injected -pre/-post/-readiness folder folds into its parent, and a component whose own name ends in one of those phases claims a record of that name rather than ceding it to a parent that does not exist.
A record matching no component is dropped, because on a real cluster that is almost everything installed. One carrying an AICR stamp annotation and matching no component is counted, and that count is the detector for a broken mapping: AICR wrote the record, so anything above zero means this package no longer recognizes its own output. It is a Helm-side signal only, since a generated Argo Application carries no such annotation.
The version comes from the stamp when it is present and from the release's chart version otherwise, the latter only for a component the registry pins an upstream chart for (ADR-021 Decision 5, plus that guard). The guard is what keeps a wrapper's version from being reported as a payload's: a manifest-only or Kustomize component is carried by an AICR-authored chart whose version is AICR's. An injected folder never supplies a version at all, for the same reason. No version is a legitimate answer and needs no sentinel, because upgrade.Match already reports an unparseable side as VerdictUnversioned.
Two exclusions are deliberate and narrow. A release is excluded only when its status is uninstalled, because `helm uninstall --keep-history` leaves a complete record and reporting it would manufacture a verdict for an upgrade nobody is making. Any other status keeps the component installed, but only deployed establishes its version: Helm writes an upgrade's target before it applies anything, so a failed, uninstalling or pending-* newest revision may name a version the cluster is not running, and reads as unversioned rather than at that target. And when several releases map to one component, the component's namespace decides which; failing to decide is an error rather than a pick, because guessing which tenant's install was meant is not this package's decision. A single unambiguous install answers whatever namespace it is in, since a recipe may legitimately deploy outside the registry default.
Helm answers first and Argo fills only what it left unanswered: argocd-helm produces both an app-of-apps Helm release and per-component Applications, and the Applications are the per-component truth.
Why Argo CD needs a reader of its own ¶
Argo CD creates no Helm release. A generated Application with a helm source is rendered with `helm template` and its manifests applied directly, so no release record is ever written and the Helm reader returns nothing for a cluster deployed with the argocd or argocd-helm deployer. The Applications are the only evidence those components are installed. (argocd-helm delegates to the argocd deployer and emits the same Applications, so one reader covers both.)
What Argo can be asked is narrower. It keeps no counterpart to a chart's annotations and no revision in Helm's sense, so those fields are left zero rather than approximated. A chart's version is read from status, never from spec: targetRevision is the pin Argo has been asked to reach, and a pin changed while its sync is pending or has failed leaves the old chart deployed. A Synced status answers with the pin it last compared; otherwise the newest history entry, which records a completed sync, does; otherwise nothing does, and the component reads as unversioned rather than at a version it may not be running. A path-based Application, which is the shape of every generated wrapper and every Kustomize component, reports no version at all: the only revision it carries is the bundle repository's git branch, and reporting that would claim each such component sits at "main".
The exception is an Application the AICR Operator wrote. It is path-based too, an OCI chart at path "." pinned by digest, but the operator records each chart's version beside its digest in a plan ConfigMap. The digest status establishes as deployed is looked up there, by release ID, in the operator's namespace only, since only that namespace is guarded by the operator's admission policy. A digest no plan records fails the read with the alternatives rather than reading every operator component as unversioned.
Only an Application deploying into this cluster is read. On an Argo CD management cluster most deploy elsewhere, and a remote one carrying a component's name and namespace would become this cluster's baseline. A destination server is this cluster only as Argo's in-cluster address; a destination name is resolved through Argo's cluster Secrets, and one that cannot be resolved, or resolves both ways, is refused rather than guessed. Remote Applications are excluded and counted.
Why it reads Kubernetes rather than Helm ¶
Helm's CLI and SDK both read release records from the Kubernetes API. This package reads the same records directly, which buys three things. One authentication path, since the Argo CD reader and the at-risk scan read the cluster through client-go anyway and a second path through the helm binary could resolve a different context. One paged List per storage driver instead of the N+1 subprocesses `helm list` plus `helm get metadata` per release would cost. And no dependency on helm.sh/helm/v4, whose linked module graph adds 38 permanently scanned modules (a WebAssembly runtime and a Postgres driver among them, retained because Helm's storage backend blank-imports them for their init side effects). That dependency was assessed and declined in #2530.
The cost is coupling to a storage encoding rather than an API. Helm's default Secret driver versions that encoding explicitly in the Secret's Type field ("helm.sh/release.v1"), unchanged across the Helm 3 to 4 major boundary, so a record written in a format this package has not been taught is identifiable as such and is refused rather than guessed at.
The ConfigMap driver writes no counterpart. Its records carry the same labels and the same encoded payload and nothing that names the format, so there is nothing to check before decoding: an unreadable ConfigMap record surfaces only as the read failing closed, on an absent or empty release key, or on base64, gzip, JSON or absent chart metadata. Reading the format out of the storage key ("sh.helm.release.v1.<name>.v<revision>") would appear to close that gap and is deliberately not done, here or anywhere else in the package: the labels are how these records are meant to be read, and an object name is not a format declaration.
The at-risk scan ¶
ScanAtRisk is advisory and asks what an upgrade might destroy rather than what is installed. Given the group/kind pairs the crossed transition records name, it resolves each through a RESTMapper and requests only its metadata, cluster-wide. A list whose continue token expires resumes from the apiserver's latest state, so objects changed in between may be missed or included. A token that keeps expiring with no page served fails the scan.
It reports every object carrying none of these ownership markers:
- a nonblank argocd.argoproj.io/tracking-id annotation
- the app.kubernetes.io/managed-by=Helm label with a nonblank meta.helm.sh/release-name annotation
- the app.kubernetes.io/managed-by=Helm label with a helm.sh/hook annotation naming a pre-upgrade or post-upgrade phase, the only hooks an upgrade re-creates
The check is positive, so an unrecognized object is at risk by default. The failure it guards is an operator's own custom resources being cascade-deleted when a CRD is removed, and over-warning about an object some fourth tool owns costs a line of output while under-warning costs the object. A kind the cluster does not serve is skipped rather than raised: the CRD a record names may simply not be installed, which is the common case for a component the operator does not run. A discovery failure is not skipped, because it has not established that, and neither is a no-match for a kind whose own API group discovery could not enumerate: client-go reports that partial failure as a bare no-match whenever other groups answered.
Nothing it returns reaches the exit code, per ADR-021 Decision 3. AICR blocking an upgrade over resources it does not own is a claim it has not earned.
What it cannot tell you ¶
A Helm release counts only from a deployed revision, and an Argo Application only from a revision a sync established. Both are records of what was applied rather than observations: a hand-edited Deployment leaves either unchanged. This answers the version question authoritatively and nothing else. Live resource state is the at-risk scan's job, and that scan in turn reports only what carries an ownership marker, not whether an object is in use.
Index ¶
- func HelmReleaseName(d Deployer, name, namespace string) (release string, ok bool)
- type ArgoInfo
- type AtRiskObject
- type AtRiskOptions
- type AtRiskResult
- type Component
- type Deployer
- type HelmInfo
- type Options
- type Record
- type Releases
- type ResourceKind
- type Result
- type ScannedKind
- type SourceInfo
- type UnprovenReason
- type UnprovenRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HelmReleaseName ¶
HelmReleaseName returns the Helm release name d stores a bundle-info.yaml release under, given that release's name and namespace. ok is false when d writes no Helm release, as argocd and argocd-helm do not, or is unknown.
Types ¶
type ArgoInfo ¶
type ArgoInfo struct {
// Read reports whether the deployer installs through Argo CD at all; see
// readsHelm. The counts below are zero when it does not.
Read bool
// Applications is every Application the read examined, including the ones
// belonging to no component.
Applications int
// Unattributed is Applications carrying no name.
Unattributed int
// Unreadable is Applications matched loosely that could not be projected.
Unreadable int
// Remote is Applications matching a component that deploy to another
// cluster, which on an Argo CD management cluster is most of them.
Remote int
// Unplaced is readable Applications matched to a component by a prefixed
// name whose destination is none of its namespaces.
Unplaced int
}
ArgoInfo accounts for the Argo CD Applications.
It has no Uninstalled or StampedUnmatched counterpart, and they are absent rather than present-and-always-zero. An Application carries no release status, so there is nothing to exclude on, and the generated Application carries no AICR annotations either — the stamp lives in the wrapper Chart.yaml the Application points at, which this never reads. The Helm-side mapping detector therefore has no Argo equivalent today.
type AtRiskObject ¶
type AtRiskObject struct {
Group string
Kind string
Components []string
Namespace string
Name string
}
AtRiskObject is one object an upgrade could disturb and nothing appears to own. Namespace is empty for a cluster-scoped object.
type AtRiskOptions ¶
type AtRiskOptions struct {
// Kubeconfig is the path to read the cluster from. Empty uses the ambient
// resolution pkg/k8s/client applies.
Kubeconfig string
// Kinds is what to look for. An empty list contacts no cluster: an upgrade
// whose crossed records name no resources has nothing to put at risk.
Kinds []ResourceKind
}
AtRiskOptions is one advisory scan.
type AtRiskResult ¶
type AtRiskResult struct {
// Kinds is one entry per requested kind, in request order, whatever came
// of it. It is what separates "checked and clean" from "the kind is not
// installed here", which an empty Findings alone conflates.
Kinds []ScannedKind
// Findings is every object carrying no recognized ownership marker.
Findings []AtRiskObject
}
AtRiskResult is what the scan looked at and what it found.
func ScanAtRisk ¶
func ScanAtRisk(ctx context.Context, opts AtRiskOptions) (AtRiskResult, error)
ScanAtRisk reports the objects an upgrade could disturb that carry no deployer ownership marker, reading the cluster opts names.
It is advisory: the caller reports what it returns and never fails a run on it, per ADR-021 Decision 3. AICR blocking an upgrade over resources it does not own is a claim it has not earned, and the same reasoning is what allows a kind the cluster does not serve to be skipped rather than raised.
type Component ¶
type Component struct {
// Name is the registry component name.
Name string
// Namespace is the component's helm.defaultNamespace. Flux composes it
// into the release name, and it is what disambiguates an Argo suffix
// match and two tenants' installs of one chart.
Namespace string
// Namespaces are further namespaces the component may have been installed
// into, which the caller knows and the registry does not: the target
// recipe's own, where an overlay or mixin moved the component (os-talos
// moves gpu-operator to privileged-gpu-operator) or --inherit-from kept
// it where it was. Every candidate is matched on equally.
Namespaces []string
// HasUpstreamChart reports helm.defaultVersion being set, which is the
// guard on the chart-version fallback: a component with no upstream chart
// is carried by an AICR-authored wrapper whose chart version is the
// wrapper's own and never the payload's.
HasUpstreamChart bool
}
Component is what the mapping layer needs to know about a registry entry. It is a local type for the reason upgrade.Component is: this package must not import pkg/recipe. recipe.InventoryComponents is the adapter.
type Deployer ¶
type Deployer string
Deployer names the deployer that installed the bundle being compared.
It is supplied by the caller rather than detected, because the cluster does not record it and the transform is not invertible: a release named gpu-operator-gpu-operator is flux's gpu-operator installed into namespace gpu-operator, or helm's component of that literal name, and nothing on the record distinguishes them.
Mirrors config.DeployerType, declared here rather than imported for the reason pkg/upgrade's canonicalDeployers gives; read_test.go carries that import and fails on drift.
const ( DeployerHelm Deployer = "helm" DeployerHelmfile Deployer = "helmfile" DeployerFlux Deployer = "flux" DeployerArgoCD Deployer = "argocd" DeployerArgoCDHelm Deployer = "argocd-helm" DeployerFleet Deployer = "fleet" DeployerTerraform Deployer = "terraform" )
The deployers a bundle can be installed with, and the only values Options.Deployer accepts.
type HelmInfo ¶
type HelmInfo struct {
// Read reports whether the deployer installs through Helm releases at
// all; see readsHelm. The counts below are zero when it does not.
Read bool
// Records is every storage object the read examined, across both drivers
// and including the ones belonging to no component. It is the denominator
// the other counts are read against.
Records int
// Unattributed is records carrying no release name, which cannot be
// attributed even to a guess.
Unattributed int
// Unreadable is releases whose version was withheld, counted once per
// release however many revisions were unreadable. That is a release
// matched loosely whose records could not be read, or a dual-driver
// release, whose records all decode.
Unreadable int
// Uninstalled is releases excluded because `helm uninstall
// --keep-history` left the record behind.
Uninstalled int
// StampedUnmatched is records carrying an AICR stamp annotation that
// matched no component under this deployer's name transform. It is the
// detector for a broken mapping: AICR wrote those records, so anything
// above zero means this package no longer recognizes its own output.
StampedUnmatched int
}
HelmInfo accounts for the Helm storage records.
type Options ¶
type Options struct {
// Kubeconfig is the path to read both clients from. Empty uses the
// ambient resolution pkg/k8s/client applies.
Kubeconfig string
// Deployer is how the bundle being compared was installed.
Deployer Deployer
// Components is the set the read answers for.
Components []Component
// OperatorNamespace is where the AICR Operator keeps the plans that
// version the Argo CD Applications it writes. Empty is
// defaults.AICROperatorNamespace. Plans are read nowhere else: only that
// namespace is guarded by the operator's admission policy.
OperatorNamespace string
}
Options is one inventory read.
type Record ¶
type Record struct {
// Source is "helm" for a Helm release or "argocd" for an Argo CD
// Application.
Source string
Name string
// Namespace is the namespace a Helm record is stored in, which helm
// uninstall takes, or an Application's destination namespace.
Namespace string
// InstallNamespace is the namespace the workload runs in, which helm
// list reports. It differs from Namespace only for a readable Flux
// record, which helm-controller stores in the HelmRelease's namespace.
InstallNamespace string
// Status is a Helm release's newest status, or empty for an Application
// or an unreadable record.
Status string
// Injected reports whether the record is an injected -pre, -post or
// -readiness folder rather than the component's own release.
Injected bool
}
Record is one release record a read attributed.
type Releases ¶
type Releases struct {
// Components maps a component name to its records, uninstalled releases
// and injected -pre, -post and -readiness folders included. It omits
// loose matches:
// - an Argo CD Application matched only by a prefixed name that
// deploys outside the component's namespaces
// - an unreadable Flux record matched only by its name's suffix
Components map[string][]Record
// Stamped holds the Helm records in any namespace that carry an AICR
// stamp but match no component, such as a retired component's release
// or one installed under another deployer's naming. A release installed
// before stamping shipped has no stamp and never appears here.
Stamped []Record
}
Releases holds every record ReadReleases attributes, in reader order, including the several installs of one component that make Read fail.
func ReadReleases ¶
ReadReleases returns the records opts.Deployer installed opts.Components under, attributed with that deployer's naming. An unreadable record fails the read only when its name is one AICR writes, and is skipped otherwise.
type ResourceKind ¶
type ResourceKind struct {
Group string
Kind string
// Components is whose upgrade named this kind, which the scan copies onto
// every finding rather than interpreting. It is what makes a finding
// actionable: the object's identity says what might be lost, and this says
// which upgrade would do it.
Components []string
}
ResourceKind is one group and kind the at-risk scan examines. An empty Group is the core API group.
It is a local type for the reason Component is: this package must not import pkg/upgrade, whose records declare these. upgrade.AffectedKinds produces the list and the caller holding both converts; atrisk_test.go carries that import so the conversion cannot drift silently.
type Result ¶
type Result struct {
// Versions maps component name to installed version. A component absent
// from the map is not installed. A component present with an empty value
// is installed at a version nothing in the cluster records comparably;
// upgrade.Match already reports that as VerdictUnversioned, so there is
// no sentinel to invent.
Versions map[string]string
// Unproven names, per component, the records that left it unversioned.
// Those are the install chosen for it, when that record could not
// establish a version, and every unplaced Application matched to it. An
// unproven record passed over for an install elsewhere is not named. A
// component unversioned only by records that were read, such as a failed
// Helm release, has no entry.
Unproven map[string][]UnprovenRecord
// Source is what was read and what was skipped.
Source SourceInfo
}
Result is the installed inventory: the version table an upgrade comparison consumes, and an account of what produced it.
type ScannedKind ¶
type ScannedKind struct {
Group string
Kind string
Components []string
// Present reports the cluster serving this kind. Examined is then how many
// objects of it were read, at risk or not; both are zero when it is not.
Present bool
Examined int
}
ScannedKind accounts for one kind the scan looked for.
type SourceInfo ¶
SourceInfo accounts for both readers separately. The two sets of counts are in different units and must never be summed: the Helm reader counts storage records, so one release with ten retained revisions contributes ten, while the Argo reader counts Applications, of which a component has one.
type UnprovenReason ¶
type UnprovenReason string
UnprovenReason is why a record placed a component without establishing its version. UnprovenUnreadable is a record the reader found and could not decode. UnprovenDualDriver is a Helm release with records under both storage drivers, whose revisions cannot be compared, so neither driver's newest is provably the release's. UnprovenUnplaced is a readable Argo CD Application matched by a prefixed name whose destination is none of the component's namespaces.
const ( UnprovenUnreadable UnprovenReason = "unreadable" UnprovenDualDriver UnprovenReason = "dual-driver" UnprovenUnplaced UnprovenReason = "unplaced" )
type UnprovenRecord ¶
type UnprovenRecord struct {
// Source is "helm" for a Helm release record or "argocd" for an Argo CD
// Application.
Source string
Name string
// Namespace is where a Helm record is stored, or an Application's
// destination. Empty for an unreadable Application that states none.
Namespace string
Reason UnprovenReason
}
UnprovenRecord is one record that placed a component without establishing its version.