stern

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: Apache-2.0 Imports: 31 Imported by: 6

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 List added in v1.19.0

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 WatchTargets added in v1.23.0

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

	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 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"`

	PodColor       *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 added in v1.23.0

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

ResourceMatcher is a matcher for Kubernetes resources

func (*ResourceMatcher) AllNames added in v1.23.0

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

AllNames returns the resource names including the aliases

func (*ResourceMatcher) Matches added in v1.23.0

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

Matches returns if name matches one of the resource names

func (*ResourceMatcher) Name added in v1.23.0

func (r *ResourceMatcher) Name() string

Name returns the resource name in singular

type ResumeRequest added in v1.24.0

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) *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 added in v1.13.1

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 added in v1.24.0

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 added in v1.24.0

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
	SinceTime    *metav1.Time
	Exclude      []*regexp.Regexp
	Include      []*regexp.Regexp
	Highlight    []*regexp.Regexp
	Namespace    bool
	TailLines    *int64
	Follow       bool
	OnlyLogLines bool
	// contains filtered or unexported fields
}

func (TailOptions) HighlightMatchedString added in v1.24.0

func (o TailOptions) HighlightMatchedString(msg string) string

func (TailOptions) IsExclude added in v1.13.0

func (o TailOptions) IsExclude(msg string) bool

func (TailOptions) IsInclude added in v1.13.0

func (o TailOptions) IsInclude(msg string) bool

func (TailOptions) UpdateTimezoneAndFormat added in v1.24.0

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 added in v1.23.0

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