stern

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RUNNING    = "running"
	WAITING    = "waiting"
	TERMINATED = "terminated"
	ALL_STATES = "all"
)
View Source
const TimestampFormatDefault = "2006-01-02T15:04:05.000000000Z07:00"

RFC3339Nano with trailing zeros

View Source
const TimestampFormatShort = "01-02 15:04:05"

time.DateTime without year

Variables

View Source
var (
	PodMatcher                   = ResourceMatcher{/* contains filtered or unexported fields */}
	ReplicationControllerMatcher = ResourceMatcher{/* contains filtered or unexported fields */}
	ServiceMatcher               = ResourceMatcher{/* contains filtered or unexported fields */}
	DaemonSetMatcher             = ResourceMatcher{/* contains filtered or unexported fields */}
	DeploymentMatcher            = ResourceMatcher{/* contains filtered or unexported fields */}
	ReplicaSetMatcher            = ResourceMatcher{/* contains filtered or unexported fields */}
	StatefulSetMatcher           = ResourceMatcher{/* contains filtered or unexported fields */}
	JobMatcher                   = ResourceMatcher{/* contains filtered or unexported fields */} // job does not have a short name
	ResourceMatchers             = []ResourceMatcher{
		PodMatcher,
		ReplicationControllerMatcher,
		ServiceMatcher,
		DeploymentMatcher,
		DaemonSetMatcher,
		ReplicaSetMatcher,
		StatefulSetMatcher,
		JobMatcher,
	}
)

Functions

func ContainerGenerator

func ContainerGenerator(ctx context.Context, config *DockerConfig, client *dockerclient.Client) (iter.Seq[types.ContainerJSON], error)

func FilteredContainerGenerator

func FilteredContainerGenerator(ctx context.Context, config *DockerConfig, client *dockerclient.Client, filter *dockerTargetFilter) (iter.Seq[*DockerTarget], error)

func List

func List(ctx context.Context, client kubernetes.Interface, config *Config) (map[string]string, error)

List returns a map of all 'app.kubernetes.io/instance' values.

func Run

func Run(ctx context.Context, client kubernetes.Interface, config *Config) error

Run starts the main run loop

func RunDocker

func RunDocker(ctx context.Context, client *dockerclient.Client, config *DockerConfig) error

func SetColorList

func SetColorList(podColors, containerColors []string) error

func WatchDockers

func WatchDockers(ctx context.Context, config *DockerConfig, filter *dockerTargetFilter, client *dockerclient.Client) (chan *DockerTarget, error)

func WatchTargets

func WatchTargets(ctx context.Context, i v1.PodInterface, labelSelector labels.Selector, fieldSelector fields.Selector, filter *targetFilter) (chan *Target, error)

Watch starts listening to Kubernetes events and emits modified containers/pods. The result is targets added.

Types

type Config

type Config struct {
	Namespaces            []string
	PodQuery              *regexp.Regexp
	ExcludePodQuery       []*regexp.Regexp
	Timestamps            bool
	TimestampFormat       string
	Location              *time.Location
	ContainerQuery        *regexp.Regexp
	ExcludeContainerQuery []*regexp.Regexp
	ContainerStates       []ContainerState
	Exclude               []*regexp.Regexp
	Include               []*regexp.Regexp
	Highlight             []*regexp.Regexp
	InitContainers        bool
	EphemeralContainers   bool
	Since                 time.Duration
	AllNamespaces         bool
	LabelSelector         labels.Selector
	FieldSelector         fields.Selector
	TailLines             *int64
	Template              *template.Template
	Follow                bool
	Resource              string
	OnlyLogLines          bool
	MaxLogRequests        int
	Stdin                 bool
	DiffContainer         bool

	Out    io.Writer
	ErrOut io.Writer
}

Config contains the config for stern

type ContainerState

type ContainerState string

func NewContainerState

func NewContainerState(stateConfig string) (ContainerState, error)

NewContainerState returns corresponding ContainerState

func (ContainerState) Match

func (stateConfig ContainerState) Match(containerState v1.ContainerState) bool

Match returns ContainerState is matched

type DockerConfig

type DockerConfig struct {
	Timestamps            bool
	TimestampFormat       string
	Location              *time.Location
	ContainerQuery        []*regexp.Regexp
	ExcludeContainerQuery []*regexp.Regexp
	Exclude               []*regexp.Regexp
	ImageQuery            []*regexp.Regexp
	Include               []*regexp.Regexp
	Highlight             []*regexp.Regexp
	Since                 time.Duration
	TailLines             int64
	Template              *template.Template
	Follow                bool
	OnlyLogLines          bool
	MaxLogRequests        int
	Stdin                 bool

	Out    io.Writer
	ErrOut io.Writer
}

Config contains the config for tailfin

type DockerTail

type DockerTail struct {
	ContainerId    string
	ContainerName  string
	ComposeProject string
	Tty            bool
	StartedAt      time.Time
	FinishedAt     string

	Options *TailOptions
	// contains filtered or unexported fields
}

func NewDockerTail

func NewDockerTail(
	client *dockerclient.Client,
	containerId string,
	containerName string,
	composeProject string,
	tty bool,
	startedAt time.Time,
	finishedAt string,
	tmpl *template.Template,
	out, errOut io.Writer,
	options *TailOptions,
) *DockerTail

func (*DockerTail) Close

func (t *DockerTail) Close()

func (*DockerTail) Print

func (t *DockerTail) Print(msg string)

func (*DockerTail) Start

func (t *DockerTail) Start(ctx context.Context) error

type DockerTarget

type DockerTarget struct {
	Id             string
	Name           string
	ComposeProject string
	Tty            bool
	StartedAt      time.Time
	FinishedAt     string
}

type FileTail

type FileTail struct {
	Options *TailOptions
	// contains filtered or unexported fields
}

func NewFileTail

func NewFileTail(tmpl *template.Template, in io.Reader, out, errOut io.Writer, options *TailOptions) *FileTail

NewFileTail returns a new tail of the input reader

func (*FileTail) ConsumeReader

func (t *FileTail) ConsumeReader(reader *bufio.Reader) error

ConsumeReader reads the data from the reader and writes into the out writer.

func (*FileTail) Print

func (t *FileTail) Print(msg string)

Print prints a color coded log message

func (*FileTail) Start

func (t *FileTail) Start() error

Start starts tailing

type Log

type Log struct {
	// Message is the log message itself
	Message string `json:"message"`

	// Node name of the pod
	NodeName string `json:"nodeName"`

	// Namespace of the pod
	Namespace string `json:"namespace"`

	// PodName of the pod
	PodName string `json:"podName"`

	// ContainerName of the container
	ContainerName string `json:"containerName"`

	// Docker compose project name
	ComposeProject string `json:"composeProject"`

	PodColor       *color.Color `json:"-"`
	ComposeColor   *color.Color `json:"-"`
	ContainerColor *color.Color `json:"-"`
}

Log is the object which will be used together with the template to generate the output.

type ResourceMatcher

type ResourceMatcher struct {
	// contains filtered or unexported fields
}

ResourceMatcher is a matcher for Kubernetes resources

func (*ResourceMatcher) AllNames

func (r *ResourceMatcher) AllNames() []string

AllNames returns the resource names including the aliases

func (*ResourceMatcher) Matches

func (r *ResourceMatcher) Matches(name string) bool

Matches returns if name matches one of the resource names

func (*ResourceMatcher) Name

func (r *ResourceMatcher) Name() string

Name returns the resource name in singular

type ResumeRequest

type ResumeRequest struct {
	Timestamp   string // RFC3339 timestamp (not RFC3339Nano)
	LinesToSkip int    // the number of lines to skip during this timestamp
}

type Tail

type Tail struct {
	NodeName      string
	Namespace     string
	PodName       string
	ContainerName string
	Options       *TailOptions
	// contains filtered or unexported fields
}

func NewTail

func NewTail(clientset corev1client.CoreV1Interface, nodeName, namespace, podName, containerName string, tmpl *template.Template, out, errOut io.Writer, options *TailOptions, diffContainer bool) *Tail

NewTail returns a new tail for a Kubernetes container inside a pod

func (*Tail) Close

func (t *Tail) Close()

Close stops tailing

func (*Tail) ConsumeRequest

func (t *Tail) ConsumeRequest(ctx context.Context, request rest.ResponseWrapper) error

ConsumeRequest reads the data from request and writes into the out writer.

func (*Tail) GetResumeRequest

func (t *Tail) GetResumeRequest() *ResumeRequest

func (*Tail) Print

func (t *Tail) Print(msg string)

Print prints a color coded log message with the pod and container names

func (*Tail) Resume

func (t *Tail) Resume(ctx context.Context, resumeRequest *ResumeRequest) error

func (*Tail) Start

func (t *Tail) Start(ctx context.Context) error

Start starts tailing

type TailOptions

type TailOptions struct {
	Timestamps      bool
	TimestampFormat string
	Location        *time.Location

	SinceSeconds    *int64
	DockerSinceTime time.Time
	SinceTime       *metav1.Time
	Exclude         []*regexp.Regexp
	Include         []*regexp.Regexp
	Highlight       []*regexp.Regexp
	Namespace       bool
	TailLines       *int64
	DockerTailLines string
	Follow          bool
	OnlyLogLines    bool
	// contains filtered or unexported fields
}

func (TailOptions) HighlightMatchedString

func (o TailOptions) HighlightMatchedString(msg string) string

func (TailOptions) IsExclude

func (o TailOptions) IsExclude(msg string) bool

func (TailOptions) IsInclude

func (o TailOptions) IsInclude(msg string) bool

func (TailOptions) UpdateTimezoneAndFormat

func (o TailOptions) UpdateTimezoneAndFormat(timestamp string) (string, error)

type Target

type Target struct {
	Node      string
	Namespace string
	Pod       string
	Container string
}

Target is a target to watch

func ListTargets

func ListTargets(ctx context.Context, i corev1client.PodInterface, labelSelector labels.Selector, fieldSelector fields.Selector, filter *targetFilter) ([]*Target, error)

ListTargets returns targets by listing and filtering pods

func (*Target) GetID

func (t *Target) GetID() string

GetID returns the ID of the object

Jump to

Keyboard shortcuts

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