Documentation
¶
Overview ¶
Package crd owns the ClusterReadiness custom resource: its embedded CRD manifest, plain JSON-tagged Go types (no codegen), and apply/status logic via the dynamic client.
Index ¶
- Constants
- Variables
- func AllTargetsReadyCondition(st Status) metav1.Condition
- func EnsureCRD(ctx context.Context, apiext apiextensionsclient.Interface) error
- func EnsureObject(ctx context.Context, dyn dynamic.Interface, name string, targets []string) error
- func GVR() schema.GroupVersionResource
- func InstallCommand(version string) string
- func InstallHint(version string) string
- func LegacyCRDInstalled(ctx context.Context, apiext apiextensionsclient.Interface) (bool, error)
- func MarkStatusError(ctx context.Context, dyn dynamic.Interface, name string, cause error, ...) error
- func ReadyCondition(st Status) metav1.Condition
- func SetTargets(ctx context.Context, dyn dynamic.Interface, name string, targets []string) (int64, error)
- func WriteStatus(ctx context.Context, dyn dynamic.Interface, name string, st Status) error
- func WriteStatusOver(ctx context.Context, dyn dynamic.Interface, name string, st Status, ...) error
- type Spec
- type Status
- type TargetStatus
- type TopFinding
Constants ¶
const ( // Group is the API group, spelled once in internal/crd/apigroup. Group = apigroup.Group Version = "v1alpha1" Kind = "ClusterReadiness" Plural = "clusterreadinesses" Singular = "clusterreadiness" // CRDName is the ClusterReadiness CustomResourceDefinition's name. CRDName = Plural + "." + Group // AnnotationPrefix starts every annotation key upgradescope reads or // writes, spelled once in internal/crd/apigroup. AnnotationPrefix = apigroup.AnnotationPrefix // DefaultName is the conventional singleton object name. DefaultName = "cluster" // StatusErrorAnnotation marks a ClusterReadiness whose status the agent // failed to write, so the verdict it still shows is not read as // current: its value is the time of the failure (RFC 3339, UTC) and a // short reason. The next successful status write removes it. StatusErrorAnnotation = apigroup.StatusErrorAnnotation )
const ( ConditionReady = "Ready" // ConditionAllTargetsReady is False when any target is blocked, Unknown // when none is blocked but any is unknown (or no target was // evaluated), True only when every target is ready. Ready keeps the // first target's meaning; this is the condition to wait on for a plan // of several targets. ConditionAllTargetsReady = "AllTargetsReady" ReasonReady = "Ready" // True: verdict ready ReasonBlocked = "Blocked" // False: at least one blocker ReasonNotAssessed = "NotAssessed" // Unknown: verdict unknown, or no target evaluated )
ConditionReady is the condition type summarizing the first target's verdict; its reasons map the three verdicts. ConditionAllTargetsReady summarizes every target and uses the same reasons.
const FieldManager = "upgradescope-agent"
FieldManager is the server-side apply field manager EnsureCRD writes the CRD spec under. Fields other managers own (GitOps labels and annotations, kubectl's last-applied annotation) are left alone.
const LegacyCRDCleanup = "kubectl delete crd " + LegacyCRDName
LegacyCRDCleanup is the command that removes the legacy CRD, and with it every ClusterReadiness object stored under the old group.
const LegacyCRDName = Plural + "." + apigroup.LegacyGroup
LegacyCRDName is the CRD v0.1.x and the v0.2.0 release candidates installed, on the group the project never owned (#68). Nothing reads or writes its objects any more; the agent only says it can be removed.
const ManifestFile = CRDName + ".yaml"
ManifestFile is the CRD's file name under the chart's crds/ directory.
const ( // MaxTargets is the most targets a ClusterReadiness evaluates, and the // maxItems of spec.targets in manifest.yaml (a test holds the two // together). Each target costs a status row, and 8 is twice the // server's --targets cap of 4: room for the two or three minors an // upgrade plan spans, and for a CI matrix, without letting a CR grow // the status without limit: the red-team measured 1.88 MB at 500 // targets and a rejected write at 1000. MaxTargets = 8 )
The status is bounded by construction, so a status write can never grow past the apiserver's request limit (3 MiB) and wedge (issue #191). Four numbers hold it: MaxTargets rows, maxTopFindings findings per row, each title and remediation clipped to a budget of encoded bytes (see clip), and a capped notAssessed. At the limits that is 8 × 20 × (512 + 1024) bytes of finding text plus 32 × 512 of notes: ~280 KiB whatever the characters are, because the budgets count what the text costs in the stored JSON, not characters (counted in characters, a title of '<' costs six bytes each and the worst case is 1.5 MiB). The full finding list lives in the server and CLI.
const UpgradeGuideURL = "https://abd-ulbasit.github.io/upgradescope/operations/upgrade/#the-api-group-moved"
UpgradeGuideURL is the migration guide from the legacy group: what to install, carry over, rename and delete, in order.
Variables ¶
var ErrCRDNotInstalled = errors.New("ClusterReadiness CRD is not installed")
ErrCRDNotInstalled means the ClusterReadiness CRD is absent and the agent may not create it. The Helm chart grants no CRD create: its crds/ directory installs the CRD on first install only, and the agent only keeps the schema current. InstallHint says how to install it.
var ErrStatusErrorNotCleared = errors.New("status written, marker not cleared")
ErrStatusErrorNotCleared is what WriteStatus returns, wrapped, when the status was written but the StatusErrorAnnotation of an earlier failure could not be removed: the status is current, only the marker outlived it.
var Manifest []byte
Manifest is the embedded ClusterReadiness CRD manifest. It is the single source of truth: EnsureCRD converges the cluster to it, and the Helm chart ships a copy in crds/.
Functions ¶
func AllTargetsReadyCondition ¶ added in v0.2.0
AllTargetsReadyCondition summarizes every target in st.Targets: False (reason Blocked) when any is blocked, Unknown (reason NotAssessed) when none is blocked but any is unknown or no target was evaluated, True (reason Ready) only when all are ready. The message names the targets that decide it, e.g. "1.38 blocked (3 blockers)". LastTransitionTime is the evaluation time; WriteStatus keeps the stored one while the status does not change.
func EnsureCRD ¶
func EnsureCRD(ctx context.Context, apiext apiextensionsclient.Interface) error
EnsureCRD keeps the ClusterReadiness CRD in step with the embedded manifest. An in-sync CRD gets no write at all. A drifted one is fixed with a forced server-side apply of the manifest under FieldManager, so the spec matches this binary while labels and annotations owned by others survive. A missing CRD is created (and waited on until Established) when the caller may create CRDs, as with an admin kubeconfig; under the chart's RBAC the create is forbidden and the error wraps ErrCRDNotInstalled.
func EnsureObject ¶
EnsureObject creates the ClusterReadiness CR if absent, with spec.targets set to targets (empty spec when there are none). It never overwrites an existing object; SetTargets does that.
func GVR ¶
func GVR() schema.GroupVersionResource
GVR is the dynamic-client resource identifier for ClusterReadiness.
func InstallCommand ¶ added in v0.2.0
InstallCommand is the command that installs the ClusterReadiness CRD from the release named by version, the binary's. Helm installs crds/ on first install only, so an upgrade needs it by hand. A version that names no release tag (a dev build) gets the placeholder <tag>, which InstallHint explains.
func InstallHint ¶ added in v0.2.0
InstallHint says how to install the CRD when the agent may not: the kubectl apply of the release's manifest, and the same from the chart's crds/ directory after helm pull. For a dev build it says which tag to use.
func LegacyCRDInstalled ¶ added in v0.2.0
LegacyCRDInstalled reports whether the legacy CRD is still installed. It only reads: deleting the CRD deletes the objects under it, which is the cluster owner's call. A failed read is returned, not taken for "absent".
func MarkStatusError ¶ added in v0.2.0
func MarkStatusError(ctx context.Context, dyn dynamic.Interface, name string, cause error, at time.Time) error
MarkStatusError annotates the ClusterReadiness with when its status write failed and why (StatusErrorAnnotation), by a merge patch of the object itself: an agent that lost only the status subresource can still say so. A role that lost patch on the object too cannot, and gets the error; its /readyz and metrics are then the only signals. cause is cut to one short line; at is the failure's time.
func ReadyCondition ¶ added in v0.2.0
ReadyCondition derives the Ready condition from the first target's verdict (the one the Ready printer column shows). LastTransitionTime is the evaluation time; WriteStatus keeps the stored one while the condition's status does not change.
func SetTargets ¶ added in v0.2.0
func SetTargets(ctx context.Context, dyn dynamic.Interface, name string, targets []string) (int64, error)
SetTargets replaces spec.targets of an existing ClusterReadiness with a merge patch, leaving the rest of the object alone. It returns the patched object's generation.
func WriteStatus ¶
WriteStatus replaces the status subresource, retrying on conflict with a fresh read each attempt. st.ObservedGeneration should be the generation whose spec was evaluated (from ReadSpec or SetTargets), so a spec edited since is not claimed as observed; zero stamps the generation of the object being written. It sets the Ready and AllTargetsReady conditions from st, keeping the stored condition's lastTransitionTime while its status is unchanged. Whatever st holds, notAssessed is bounded here (boundNotAssessed), the one place every source of notes passes.
func WriteStatusOver ¶ added in v0.2.0
func WriteStatusOver(ctx context.Context, dyn dynamic.Interface, name string, st Status, current *unstructured.Unstructured) error
WriteStatusOver is WriteStatus whose first attempt writes over current, the object as the caller read it moments before (ReadSpecObject), instead of reading it again (#228): the update carries current's resourceVersion, so an object changed since is a conflict, and the retry reads it fresh. A nil current reads it first, as WriteStatus does.
Types ¶
type Spec ¶
type Spec struct {
// Targets are Kubernetes minor versions to evaluate against, e.g. ["1.36","1.37"].
// Empty → agent defaults to next minor above the observed server version.
Targets []string `json:"targets,omitempty"`
// Ignore accepts findings, as .upgradescope.yaml's ignore list does;
// the agent applies it every tick. File globs never match live objects.
Ignore []suppress.Rule `json:"ignore,omitempty"`
}
func ReadSpec ¶
func ReadSpec(ctx context.Context, dyn dynamic.Interface, name string) (spec Spec, generation int64, found bool, err error)
ReadSpec returns the ClusterReadiness spec and the metadata.generation it was read at, for WriteStatus to stamp as observed. found=false (with nil error) means the object does not exist; callers typically EnsureObject then.
func ReadSpecObject ¶ added in v0.2.0
func ReadSpecObject(ctx context.Context, dyn dynamic.Interface, name string) (spec Spec, generation int64, obj *unstructured.Unstructured, err error)
ReadSpecObject is ReadSpec returning the object read as well (nil when it does not exist, with a nil error), for WriteStatusOver to write the status over without reading it again.
type Status ¶
type Status struct {
ObservedServerVersion string `json:"observedServerVersion,omitempty"`
KBVersion string `json:"kbVersion,omitempty"`
LastEvaluated metav1.Time `json:"lastEvaluated,omitempty"`
Targets []TargetStatus `json:"targets,omitempty"`
NotAssessed []string `json:"notAssessed,omitempty"` // "helm: secrets list forbidden"
AgentVersion string `json:"agentVersion,omitempty"`
// AddOnEvidenceAgeSeconds is engine.Report.AddOnEvidenceAgeSeconds: how
// old the pod evidence the add-ons were detected from was when the agent
// reused its last full pod pass (#228); absent when every pod was read.
AddOnEvidenceAgeSeconds int64 `json:"addOnEvidenceAgeSeconds,omitempty"`
// SupportPhase, ExtendedSupportFrom, ExtendedSupportEnds,
// AnnualCostDelta, Currency, PriceAsOf, AnnualCostNote and
// ExtendedSupportCondition are the engine's Report.Support for a cluster on EKS, GKE
// or AKS whose Kubernetes minor the provider dataset dates: where
// the minor stands in the provider's support calendar (standard,
// ending, extended, ended), the day extended support begins
// (YYYY-MM-DD) and, where the provider offers any, the day it ends, and, only where the provider's price is cited, what
// extended support adds per cluster per year at list price and the day
// that price was read. Phases ending and extended are the provider's
// calendar: where extended support is opt-in (GKE, AKS) it applies to
// this cluster only if ExtendedSupportCondition holds, and
// AnnualCostNote says whom the price is charged to. They are the
// cluster's, the same for every target, and absent otherwise.
SupportPhase string `json:"supportPhase,omitempty"`
ExtendedSupportFrom string `json:"extendedSupportFrom,omitempty"`
ExtendedSupportEnds string `json:"extendedSupportEnds,omitempty"`
AnnualCostDelta string `json:"annualCostDelta,omitempty"`
Currency string `json:"currency,omitempty"`
PriceAsOf string `json:"priceAsOf,omitempty"`
// AnnualCostNote and ExtendedSupportCondition are the provider's
// caveats, carried so a status reader does not take the figure or the
// phase for a fact about this cluster's configuration.
AnnualCostNote string `json:"annualCostNote,omitempty"`
ExtendedSupportCondition string `json:"extendedSupportCondition,omitempty"`
// ObservedGeneration is the metadata.generation whose spec was
// evaluated (WriteStatus stamps the current one when it is zero), and
// Conditions carry the Ready condition (ReadyCondition, the first
// target) and AllTargetsReady (AllTargetsReadyCondition): the standard
// shape Argo CD, kstatus and `kubectl wait` read.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
// ReadyGaps labels the first target's gaps (engine.CapabilityGap.Label,
// required ones marked) for the Ready condition message. Not stored:
// whether a gap is required depends on the target, and NotAssessed is
// the union over all targets.
ReadyGaps []string `json:"-"`
}
func StatusFromReports ¶
func StatusFromReports(reports []engine.Report, observedServerVersion, agentVersion string, now time.Time) Status
StatusFromReports builds the full CRD status from per-target reports. All reports come from the same inventory, so KBVersion is taken from the first report. NotAssessed is the deduped union over all reports, in first- seen order — most gaps are per-inventory, but kb-coverage is per-target. Gaps render as "capability: reason", a partial one as "capability (partial): reason; skipped: a, b". Whether a gap is required depends on the target, so only the Ready condition, which reads the first target, says that.
type TargetStatus ¶
type TargetStatus struct {
Target string `json:"target"` // "1.36"
Score int `json:"score"`
Ready bool `json:"ready"` // == (Verdict == "ready"); kept for v0.1 readers
Verdict string `json:"verdict,omitempty"` // "ready" | "blocked" | "unknown" (engine.Verdict)
Blockers int `json:"blockers"`
Warnings int `json:"warnings"`
Infos int `json:"infos"`
Suppressed int `json:"suppressed,omitempty"` // accepted by spec.ignore or annotations; not in the counts above
ByCategory map[string]int `json:"byCategory,omitempty"` // category → count
TopFindings []TopFinding `json:"topFindings,omitempty"` // ≤20, severity-sorted
}
func TargetStatusFromReport ¶
func TargetStatusFromReport(r engine.Report) TargetStatus
TargetStatusFromReport summarizes one engine.Report for CRD status: severity/category counts over all findings, plus the first maxTopFindings findings (Report.Findings is already severity-sorted per engine contract).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apigroup is the one place the project's Kubernetes API group is spelled: the ClusterReadiness CRD's group and the prefix of every annotation upgradescope reads or writes.
|
Package apigroup is the one place the project's Kubernetes API group is spelled: the ClusterReadiness CRD's group and the prefix of every annotation upgradescope reads or writes. |