Documentation
¶
Overview ¶
Package agent runs the in-cluster continuous loop: collect → evaluate per target → ClusterReadiness CRD status (always) → push snapshot to the server on content change. The agent's local value never depends on server availability (spec §3).
Index ¶
- Variables
- func CleartextPushWarning(serverURL, token string) string
- func LoadServerCAs(file string) (*x509.CertPool, error)
- func Run(ctx context.Context, clients collect.Clients, dyn dynamic.Interface, ...) error
- func ValidateForceSyncEvery(d time.Duration) error
- func ValidateInterval(d time.Duration) error
- func ValidatePodPassEvery(n int) error
- func ValidatePodPassMaxAge(d time.Duration) error
- func ValidatePprofAddr(addr string) error
- func ValidateServerToken(tok string) error
- func ValidateServerURL(raw string) error
- type Config
Constants ¶
This section is empty.
Variables ¶
var AgentVersion = "dev"
AgentVersion is stamped into CRD status and push envelopes. The CLI sets it from the build version; "dev" otherwise.
Functions ¶
func CleartextPushWarning ¶ added in v0.2.0
CleartextPushWarning says why pushing to serverURL with token is unsafe, or returns "": a bearer token sent over plain http:// to a host that is not loopback crosses the network in the clear, where anyone on the path can replay it — and the shared ingest token may push as any cluster.
func LoadServerCAs ¶ added in v0.2.0
LoadServerCAs is the system root pool plus the PEM certificates in file (agent --server-ca-file), for a server whose certificate a private CA issued. A file without one certificate in it, or with a CERTIFICATE block that does not parse, is an error, not a pool missing a CA: that would fail every push later with a less useful one. Other PEM block types are skipped, as AppendCertsFromPEM skips them.
func Run ¶
func Run(ctx context.Context, clients collect.Clients, dyn dynamic.Interface, apiext apiextensionsclient.Interface, k kb.KB, cfg Config) error
Run executes the continuous loop until ctx is canceled (returns nil — a cancel is a graceful stop, not an error). The first tick runs immediately; later ticks fire every Interval ±10% jitter, each under tickTimeout. Every tick logs one line and updates the metrics; tick errors are never fatal: the loop never dies on a tick error. With HealthAddr set, /healthz, /readyz and /metrics are served until Run returns.
func ValidateForceSyncEvery ¶ added in v0.2.0
ValidateForceSyncEvery rejects a force-sync period that is not positive. Config treats a zero ForceSyncEvery as unset (1h), but a caller that was given one explicitly (--force-sync-every) must not have 0 silently mean the default, nor a negative period mean every tick (#238). A period at or below the interval is not refused: it means every tick (forceSyncInEffect), and Run says so.
func ValidateInterval ¶ added in v0.2.0
ValidateInterval rejects an evaluation interval below the 1m minimum. Zero is below it: Config treats a zero Interval as unset, but a caller that was given an interval explicitly (the --interval flag) must not have 0 silently mean the default.
func ValidatePodPassEvery ¶ added in v0.2.0
ValidatePodPassEvery rejects a --pod-pass-every below 1. Config treats a zero PodPassEvery as unset (3), but a caller that was given one explicitly must not have 0 silently mean the default; 1 lists every pod every tick.
func ValidatePodPassMaxAge ¶ added in v0.2.0
ValidatePodPassMaxAge rejects a --pod-pass-max-age that is not positive: a full read of the pods could never be put off for a duration of zero or less, and 0 must not silently mean the default (#228).
func ValidatePprofAddr ¶ added in v0.2.0
ValidatePprofAddr rejects a --pprof-addr that is not a loopback host and port ("127.0.0.1:6060", "localhost:6060", "[::1]:6060"; "" is off). A profile lets whoever can fetch it read the process's heap and goroutine stacks, so the profiler never listens on a port without a host, nor on a wildcard or a routable address (#247).
func ValidateServerToken ¶ added in v0.2.0
ValidateServerToken rejects a push token no request could carry: one with whitespace or control characters in it. A trailing newline (a Secret made from a file with one) made every push fail with an invalid Authorization header, retried as if the server were down (#238). Callers reading a token from a file or the environment trim its surrounding whitespace first; what is left must have none.
func ValidateServerURL ¶ added in v0.2.0
ValidateServerURL rejects a --server-url no push could reach: anything but an http or https URL with a host. Without a scheme ("fleet.example.com") or with another one, every push would fail with "unsupported protocol scheme", retried as if the server were down (#238).
Types ¶
type Config ¶
type Config struct {
Interval time.Duration // default 10m, min 1m
ServerURL string // optional; "" = CRD-only mode
ServerToken string // bearer for push
// ServerTokenFile, when set, is the file the push token is read from,
// in place of ServerToken: a mounted Secret. It is read at start (a
// missing, empty or unacceptable file fails it) and re-read when it
// changes, checked at most every 5 seconds when a push is made, so a
// rotated token needs no restart. A new file that is empty or unreadable
// leaves the old token in use and is logged, naming the file and never
// the token.
ServerTokenFile string
ClusterName string // human label sent to server; default = ClusterID
CRName string // default crd.DefaultName
TeamLabel string // default "team"
ForceSyncEvery time.Duration // default 1h: push even if hash unchanged
// PodPassEvery and PodPassMaxAge set how often the agent lists every pod
// outside kube-system: every PodPassEvery ticks (the pass is the first
// of them), and sooner when the last full pass is PodPassMaxAge old; in
// between, add-ons are detected from that pass's images and labels, so
// an add-on installed or upgraded since (other than through a Helm
// release or GitOps chart reference, whose change forces a full pass) is
// reported as it was for at most PodPassEvery-1 ticks, and a pass
// PodPassMaxAge old is not reused (#228).
// Defaults collect.DefaultPodPassEvery (3) and
// collect.DefaultPodPassMaxAge (1h); 1 lists every pod every tick.
PodPassEvery int
PodPassMaxAge time.Duration
// ServerRootCAs verifies the server's certificate on pushes (from
// LoadServerCAs: the system roots plus a private CA); nil = the system
// roots.
ServerRootCAs *x509.CertPool
// Targets, when non-empty, are the source of truth for spec.targets:
// every tick reconciles the CR to them, overriding kubectl edits. Empty
// leaves spec.targets to whoever edits the CR. applyDefaults normalizes
// each to MAJOR.MINOR ("v1.38" → "1.38", "1.37.2" → "1.37").
Targets []string
// HelmNamespaces, when non-empty, are the only namespaces Helm release
// storage is read in (--helm-namespaces, #344): for a role that grants
// Secrets and ConfigMaps there alone (the chart's
// rbac.helmSecretsNamespaces). The helm capability is then partial,
// saying releases elsewhere were not assessed. Empty reads the whole
// cluster (collect.Options.HelmNamespaces).
HelmNamespaces []string
// SkipCRDManagement leaves the CRD alone entirely (--manage-crd=false):
// no read, no schema upgrade. The default keeps it in step with the
// embedded manifest at startup.
SkipCRDManagement bool
// HealthAddr is where /healthz, /readyz and /metrics listen, e.g.
// ":8081"; "" serves none of them.
HealthAddr string
// PprofAddr, when set, serves the Go profiler (/debug/pprof/) on its
// own listener, apart from the health one. Loopback only
// (ValidatePprofAddr): a profile exposes the process's memory and
// goroutines, and only a pod's own network namespace (kubectl
// port-forward) should reach it. "" serves none (#247).
PprofAddr string
// Logger receives the startup line and one line per tick; nil uses
// slog.Default().
Logger *slog.Logger
// contains filtered or unexported fields
}