k8slog

package
v0.0.0-...-05e7d12 Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidResourceType is returned when the given resource type is invalid
	ErrInvalidResourceType = errors.New("invalid resource type")
)

Functions

This section is empty.

Types

type Client

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

Client allows to retrieve logs of differents resources on k8s

func New

func New(k8s *kubernetes.Clientset, opts ...Opts) *Client

New creates a new Client

func (Client) Logs

func (c Client) Logs(ress ...string) (<-chan LogLine, error)

Logs retrieve logs of on or multiple resource.

A resource can be a pod, a deployment, a statefulsets, etc. It can has the following forms:

  • X/Y/Z: all the pods of the resource "Z" of type "Y" in namespace "X"
  • Y/Z: all the pods of the resource "Z" of type "Y" in namespace "default"
  • Z: the pod "Z" in namespace "default"

Examples:

  • mysvc-abcd: the pod "mysvc-abcd" in namespace "default"
  • deploy/mysvc: all the pods of the deployment "mysvc" in namespace "default"
  • prod/deploy/mysvc: all the pods of the deployment "mysvc" in namespace "prod"

type Deployment

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

Deployment is a deployment resource

func (Deployment) GetLogs

func (d Deployment) GetLogs(opts *k8s.PodLogOptions) (<-chan LogLine, error)

GetLogs retrieve logs for the deployment resource

This will get logs from all the pods matching the deployment selector

type LogLine

type LogLine struct {

	// Pod is the name of the pod
	Pod string
	// Line is the log line itself
	Line string
	// contains filtered or unexported fields
}

LogLine is a log line of a pod

type Opts

type Opts func(c *Client)

Opts is an option used to configure Client

func WithOptsFollow

func WithOptsFollow(value bool) Opts

WithOptsFollow enable to follow log stream (default: false).

If the follow option is enabled, the client will follow the log stream of the resources. If the given resource type is not a pod, the client will also watch for new pods of the resource.

func WithOptsJSONFields

func WithOptsJSONFields(fields ...string) Opts

WithOptsJSONFields configure the json option (default: none).

If enabled, log lines will be handled as JSON objects and only the given fields will be printed.

func WithOptsTimestamps

func WithOptsTimestamps(value bool) Opts

WithOptsTimestamps enable timestamps at the beginning of the log line (default: true)

type Pod

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

Pod is a pod resource

func (Pod) GetLogs

func (p Pod) GetLogs(opts *k8s.PodLogOptions) (<-chan LogLine, error)

GetLogs retrieve logs for the pod resource

type ReplicaSet

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

ReplicaSet is a ReplicaSet resource

func (ReplicaSet) GetLogs

func (rs ReplicaSet) GetLogs(opts *k8s.PodLogOptions) (<-chan LogLine, error)

GetLogs retrieve logs for the ReplicaSet resource

This will get logs from all the pods matching the ReplicaSet selector

type Resource

type Resource interface {
	GetLogs(*k8s.PodLogOptions) (<-chan LogLine, error)
}

Resource is a k8s resource (namespace/type/name)

func NewResource

func NewResource(k8s *k8s.Client, res string) (Resource, error)

NewResource creates new Resource object

A resource can be a pod, a deployment, a statefulsets, etc. It can has the following forms:

  • X/Y/Z: all the pods of the resource "Z" of type "Y" in namespace "X"
  • Y/Z: all the pods of the resource "Z" of type "Y" in namespace "default"
  • Z: the pod "Z" in namespace "default"

Examples:

  • mysvc-abcd: the pod "mysvc-abcd" in namespace "default"
  • deploy/mysvc: all the pods of the deployment "mysvc" in namespace "default"
  • prod/deploy/mysvc: all the pods of the deployment "mysvc" in namespace "prod"

Lists of resource type:

  • pod, po
  • deployment, deploy

type ResourceType

type ResourceType int

ResourceType represents a k8s resource type

const (
	// TypeUnknown is an unknown resource type
	TypeUnknown ResourceType = iota
	// TypePod is the resource type for pods
	TypePod
	// TypeDeploy is the resource type for deployments
	TypeDeploy
	// TypeStatefulSet is the resource type for statefulsets
	TypeStatefulSet
	// TypeReplicaSet is the resource type for replicasets
	TypeReplicaSet
	// TypeService is the resource type for services
	TypeService
)

type Service

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

Service is a Service resource

func (Service) GetLogs

func (s Service) GetLogs(opts *k8s.PodLogOptions) (<-chan LogLine, error)

GetLogs retrieve logs for the Service resource

This will get logs from all the pods matching the Service selector

type StatefulSet

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

StatefulSet is a statefulset resource

func (StatefulSet) GetLogs

func (ss StatefulSet) GetLogs(opts *k8s.PodLogOptions) (<-chan LogLine, error)

GetLogs retrieve logs for the statefulset resource

This will get logs from all the pods matching the statefulset selector

Jump to

Keyboard shortcuts

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