Documentation
¶
Overview ¶
Package cluster reads Kubernetes pod logs for investigation (read-only) via the client-go CoreV1 GetLogs API. It backs the controller_logs tool, which surfaces why a Flux controller failed to reconcile a source/object.
Index ¶
- type Reader
- func (r *Reader) Events(ctx context.Context, namespace, objectName string, warnOnly bool) ([]providers.KubeEvent, error)
- func (r *Reader) EventsSince(ctx context.Context, namespace, objectName string, warnOnly bool, ...) ([]providers.KubeEvent, error)
- func (r *Reader) PodLogs(ctx context.Context, q providers.PodLogQuery) (providers.LogResult, error)
- func (r *Reader) PodStatuses(ctx context.Context, namespace, labelSelector string) ([]providers.PodStatus, error)
- func (r *Reader) WorkloadOwnership(ctx context.Context, namespace, labelSelector, podName string) (providers.OwnerChain, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads pod logs via a client-go clientset (read-only).
func (*Reader) Events ¶
func (r *Reader) Events(ctx context.Context, namespace, objectName string, warnOnly bool) ([]providers.KubeEvent, error)
Events returns recent Events in a namespace (optionally for one object, optionally Warning-only), most-recent first. It is EventsSince with no time window — kept for the KubeReader interface and existing callers.
func (*Reader) EventsSince ¶ added in v0.9.0
func (r *Reader) EventsSince(ctx context.Context, namespace, objectName string, warnOnly bool, sinceMinutes int) ([]providers.KubeEvent, error)
EventsSince returns recent Events in a namespace, dropping any older than sinceMinutes (0 = no lower bound), most-recent first.
K2: the old code fetched a single Limit:200 page and only sorted newest-first AFTER fetching — so in a busy namespace the newest events could sit on a page never fetched. When a window is set we walk pages (bounded by eventMaxPages) and keep every in-window event, so the newest in-window events are actually returned.
func (*Reader) PodLogs ¶
PodLogs returns recent log lines from up to maxPods pods selected by q, bounded to the last q.SinceMinutes. When q.Previous is true it reads each pod's last-terminated container (the crash output of a CrashLoopBackOff) instead of the running one. Each line is prefixed with "<pod>/<container>". Best-effort: a pod whose log stream fails still emits a marker line so a tool error reads as missing data, not silence.
B6 (CORE-706): every container of a pod is read explicitly. The old code set no Container in PodLogOptions, and the Kubernetes API REJECTS a log request on a pod with more than one container ("a container name must be specified…"); that error was swallowed, so every pod with an istio/linkerd/cloudsql sidecar silently yielded nothing.
func (*Reader) PodStatuses ¶
func (r *Reader) PodStatuses(ctx context.Context, namespace, labelSelector string) ([]providers.PodStatus, error)
PodStatuses returns pod health in a namespace (optional label selector), with per-container waiting/terminated reasons — surfacing pod-level failures (CreateContainerConfigError, ImagePullBackOff, CrashLoopBackOff) that never reach logs because the container never started. Unhealthy pods sort first.
func (*Reader) WorkloadOwnership ¶ added in v0.9.0
func (r *Reader) WorkloadOwnership(ctx context.Context, namespace, labelSelector, podName string) (providers.OwnerChain, error)
WorkloadOwnership resolves the owner chain for the pods selected by (namespace, labelSelector) — Pod → ReplicaSet → Deployment (or StatefulSet/DaemonSet/Job) — then reads the top controller's Flux/ArgoCD tracking labels to name the owning GitOps object, and computes the generic last-applied-configuration drift signal on the top controller. It picks podName when set, else the first pod the selector returns. A selector matching no pods is an error (missing data), not a silent empty chain.