k8s

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch added in v0.1.29

func Fetch(ctx context.Context, client kubernetes.Interface, pods []corev1.Pod, request Request) ([]logs.LogResult, error)

Fetch reads logs from the already-resolved pods. Target discovery belongs to the query provider so one selector and one resource cap govern every kind.

func Follow added in v0.1.29

func Follow(ctx context.Context, client kubernetes.Interface, target Target, request Request, emit func(logs.LogResult)) error

Follow tails one container, handing emit each line as the kubelet sends it. It blocks until the container's stream ends or ctx is cancelled, which is what makes a live view a read rather than a poll.

A line arrives with the same id a collected read would have stamped it with, so a tail started from a page's position (Request.After) continues that walk instead of beginning a second one, and repeats nothing the page served.

Each line comes as its own LogResult because the attribution a collected read carries once per container has nowhere else to live when the lines arrive one at a time, and a row missing its pod and namespace is a row a live view cannot column the way a paged one does.

func SelectPods added in v0.1.29

func SelectPods(pods []corev1.Pod, selectors types.ResourceSelectors) []corev1.Pod

SelectPods narrows already-resolved pods to those a selection matches. An empty selection matches everything, so a caller with nothing to narrow by passes it through unchanged.

It exists as its own gate rather than as more entries on Request.Pods because ResourceSelectors are a union: one list holding a profile's declared pods and an operator's picked pod would read the two as alternatives and return both.

Types

type Position added in v0.1.29

type Position struct {
	Timestamp time.Time
	ID        string
}

Position identifies one log line within the ascending (timestamp, id) order.

type Request

type Request struct {
	logs.LogsRequestBase `json:",inline" yaml:",inline" template:"true"`

	// Logs will include pods that match any of these selectors.
	//
	// This applies when retrieving logs at a higher resource level,
	// such as fetching logs for a deployment spanning multiple pods.
	Pods types.ResourceSelectors `json:"pods,omitempty"`

	// Containers filters logs from only these containers.
	Containers types.MatchExpressions `json:"containers,omitempty"`

	// After resumes a forward walk immediately past a line already read.
	//
	// The kubelet has no cursor and SinceTime only names whole seconds, so a
	// resume re-reads from the start of that second and this is what discards
	// the part already served. Lines are compared on (timestamp, id), which is
	// the order the provider declares.
	After *Position `json:"-"`

	// Follow keeps the kubelet's connection open once it has served what the
	// container already wrote, so the read ends when the container or the
	// caller does rather than at the last line already in the buffer. It is
	// what Follow() sets; a collected read leaves it clear.
	Follow bool `json:"-"`
}

Request represents available parameters for Kubernetes log queries.

+kubebuilder:object:generate=true

func (*Request) DeepCopy

func (in *Request) DeepCopy() *Request

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Request.

func (*Request) DeepCopyInto

func (in *Request) DeepCopyInto(out *Request)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type Target added in v0.1.29

type Target struct {
	Pod corev1.Pod

	// Container is empty when the request named none. That is not an unknown
	// container: the kubelet then serves the pod's first, which is what
	// Metadata reports.
	Container string
}

Target is one container's log stream: the pod holding it and, when the request named containers, which of them to read.

It exists because a collected read and a tail select exactly the same streams and differ only in how they consume them — one walks them in turn, the other follows all of them at once — and a second selector would be a second answer to which containers a profile covers.

func Targets added in v0.1.29

func Targets(pods []corev1.Pod, request Request) []Target

Targets expands pods into the container streams request selects.

func (Target) Metadata added in v0.1.29

func (t Target) Metadata() map[string]any

Metadata names where this target's lines came from. Without it a caller reading many containers cannot tell which pod a line belongs to — Host carries the pod name, but the namespace and container would be lost entirely.

Jump to

Keyboard shortcuts

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