timeline

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 15 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

Overview

Package timeline reconstructs an application's history from the cluster.

kubeside writes nothing to disk, so it records no history of its own. It does not need to: Kubernetes already retains substantial history in ReplicaSets, ControllerRevisions, Helm release secrets, pod termination states, and events. Nobody assembles it, which is the actual gap this package closes.

Two rules govern everything here. Each source degrades independently: a forbidden Helm secret is a normal answer for a read-only prod role, so the timeline renders from the others and names what is missing. And where reconstruction runs out, it says why. Silence before a horizon means "not known", never "nothing happened", because rendering an empty axis as a quiet period misleads exactly the person under the most pressure.

Index

Constants

View Source
const (
	KindDeploy  = "deploy"
	KindRelease = "release"
	KindRestart = "restart"
	KindScale   = "scale"
	KindWarning = "warning"
	// KindHealth is a live transition kubeside watched happen, rather than
	// something reconstructed from the cluster's own records.
	KindHealth = "health"
	// KindExec records somebody opening a shell in a container. A shell in
	// production is an event, not a page view.
	KindExec = "exec"
	// KindBreakGlass records somebody arming an environment for writes.
	// Arming production is an event, not a setting.
	KindBreakGlass = "break-glass"
	// KindReveal records that somebody read a secret value through kubeside.
	// Reading a production credential should leave a trace in the same place
	// every other change does.
	KindReveal  = "reveal"
	KindRun     = "run"
	KindSession = "session"
)

Entry kinds.

View Source
const (
	ActorUnknown = ""
	ActorKubectl = "kubectl"
	ActorHelm    = "helm"
	ActorArgoCD  = "argocd"
	ActorHPA     = "hpa"
)

Actor kinds. Attribution comes from managedFields where it is derivable.

View Source
const ActorAutoscaler = "autoscaler"

ActorAutoscaler is an autoscaler, whose changes are expected rather than out-of-band.

View Source
const ActorController = "controller"

ActorController is a Kubernetes controller acting on its own, which is not somebody to ask about the change.

View Source
const AttributionWindow = time.Minute

AttributionWindow is how close a manager's write must be to a rollout to be called its cause. A rollout follows its trigger within seconds.

Variables

This section is empty.

Functions

func FromControllerRevisions

func FromControllerRevisions(revs []appsv1.ControllerRevision, owner types.UID) ([]Entry, *Horizon)

FromControllerRevisions does the same for StatefulSets and DaemonSets, which keep their history as ControllerRevisions rather than ReplicaSets.

func FromEvents

func FromEvents(events []corev1.Event, keep func(corev1.Event) bool) ([]Entry, *Horizon)

FromEvents keeps the warnings still inside the apiserver's TTL.

Normal events are dropped: a timeline of image pulls buries the probe failure that explains the incident.

keep selects this app's events, but the horizon is computed over all of them. The oldest event in the namespace is where the apiserver's retention actually ends; the oldest event for one app is just when that app last had something to say, and dating the horizon there would claim a cut that is not real.

func FromReplicaSets

func FromReplicaSets(sets []appsv1.ReplicaSet, owner types.UID) ([]Entry, *Horizon)

FromReplicaSets turns a Deployment's ReplicaSets into rollout history.

Every ReplicaSet the cluster still holds is one revision that shipped, with the image it shipped. The horizon is the oldest survivor: everything before it was pruned by revisionHistoryLimit and is genuinely unknowable.

Types

type Actor

type Actor struct {
	// Kind is the normalized label: kubectl, helm, argocd, hpa, or empty.
	Kind string `json:"kind,omitempty"`
	// Name is the raw field manager, kept because an unrecognized manager is
	// still information: it names the controller that did this.
	Name string `json:"name,omitempty"`
}

Actor is who made a change, when the cluster can tell us.

type Entry

type Entry struct {
	At     time.Time `json:"at"`
	Kind   string    `json:"kind"`
	Title  string    `json:"title"`
	Detail string    `json:"detail,omitempty"`
	// Source names where this was reconstructed from, so a developer can tell
	// an assembled fact from a live one.
	Source   string `json:"source"`
	Revision string `json:"revision,omitempty"`
	Image    string `json:"image,omitempty"`
	Pod      string `json:"pod,omitempty"`
	Actor    Actor  `json:"actor,omitzero"`
}

Entry is one thing that happened.

func Attribute

func Attribute(entries []Entry, fields []metav1.ManagedFieldsEntry) []Entry

Attribute assigns an actor to the entries a manager can be matched to.

Matching is by time: a rollout that happened when a manager wrote is that manager's doing. An entry outside the window keeps no actor, because a wrong name on a prod change is worse than no name.

func FromHelmSecrets

func FromHelmSecrets(secrets []metav1.PartialObjectMetadata, release string) []Entry

FromHelmSecrets reads release history from the secrets Helm writes.

The labels carry everything the axis needs, so the gzipped release payload is never decoded: less to go wrong, and nothing sensitive is touched.

func FromPods

func FromPods(pods []corev1.Pod) []Entry

FromPods recovers crashes from what the kubelet still reports.

lastState reaches exactly one termination back, so this is the last crash and never the one before it. The restart count says how many there have been, which is the honest way to say the rest are gone.

func Merge

func Merge(sets ...[]Entry) []Entry

Merge combines entries from every source, newest first.

type Gap

type Gap struct {
	Source string `json:"source"`
	Reason string `json:"reason"`
}

Gap is a source that could not be read at all.

type Horizon

type Horizon struct {
	At     time.Time `json:"at"`
	Source string    `json:"source"`
	Reason string    `json:"reason"`
	// Pruned is false when the source still holds the beginning of the app's
	// history, so the UI marks a start rather than a cut.
	Pruned bool `json:"pruned"`
}

Horizon is where one source ran out, and why.

type KubeReleases added in v1.0.1

type KubeReleases struct {
	Client metadata.Interface
}

KubeReleases lists Helm's release Secrets as metadata.

The metadata client sends Accept: application/json;as=PartialObjectMetadata, so the apiserver strips everything but the object's metadata before it answers. That is the whole point: this package wants four labels and a creation timestamp, and a helm.sh/release.v1 payload is a gzipped release whose chart values routinely carry real credentials. Asking for less means less crosses the wire, and nothing that matters ever reaches this process.

func (KubeReleases) ListReleases added in v1.0.1

func (k KubeReleases) ListReleases(ctx context.Context, namespace, selector string) ([]metav1.PartialObjectMetadata, error)

ListReleases returns the metadata of the secrets matching selector.

type Releases added in v1.0.1

type Releases interface {
	ListReleases(ctx context.Context, namespace, selector string) ([]metav1.PartialObjectMetadata, error)
}

Releases lists the metadata of the Secrets Helm writes for one release.

Metadata only, deliberately. A helm.sh/release.v1 payload is a gzipped release carrying chart values that routinely include real credentials, and this package wants four labels and a creation timestamp. Listing the objects typed would pull every payload across the wire and into the heap to read them, which is a cost and an exposure with nothing on the other side.

type ReleasesUnavailable added in v1.0.1

type ReleasesUnavailable struct{ Reason string }

ReleasesUnavailable stands in when no metadata reader could be built for a context. It fails rather than returning nothing, because "no releases" and "I could not look" are different facts and the timeline renders them differently.

func (ReleasesUnavailable) ListReleases added in v1.0.1

ListReleases always fails, carrying the reason.

type Target

type Target struct {
	Namespace string
	Name      string
	// Kind selects which rollout source applies: Deployments keep history in
	// ReplicaSets, StatefulSets and DaemonSets in ControllerRevisions.
	Kind string
	// UID is the workload's own UID, which is how history is attributed to
	// this app rather than to a same-named one that was deleted and recreated.
	UID types.UID
	// Pods are the pods currently backing the workload, from the grouping
	// engine.
	Pods []string
}

Target is the workload to reconstruct.

type Timeline

type Timeline struct {
	Entries  []Entry   `json:"entries"`
	Horizons []Horizon `json:"horizons,omitempty"`
	Gaps     []Gap     `json:"gaps,omitempty"`
}

Timeline is the assembled history.

func Reconstruct

func Reconstruct(ctx context.Context, client kubernetes.Interface, releases Releases, t Target) Timeline

Reconstruct assembles a target's history from what the cluster still holds.

Every source is read independently and a failure in one is recorded as a gap rather than returned as an error. A read-only prod role that cannot read secrets still gets rollouts, crashes, and warnings, with one line explaining what Helm history would have added.

func (*Timeline) AddGap

func (t *Timeline) AddGap(source string, err error)

AddGap records a source that could not be read.

func (*Timeline) AddHorizon

func (t *Timeline) AddHorizon(h *Horizon)

AddHorizon records where a source ran out.

Jump to

Keyboard shortcuts

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