podwatcher

package
v0.0.0-...-7da9e04 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultStagingExecutorEntrypoint   = "/packs/executor"
	DefaultStagingDownloaderEntrypoint = "/packs/downloader"
	DefaultStagingUploaderEntrypoint   = "/packs/uploader"
	DefaultRuntimeEntrypoint           = "/lifecycle/launch"
	DefaultFailGracePeriod             = "5"
	DefaultSuccessGracePeriod          = "5"
)

https://github.com/cloudfoundry-incubator/eirini-staging/tree/master/image

Variables

This section is empty.

Functions

func ExtractContainersFromPod

func ExtractContainersFromPod(pod *corev1.Pod) map[string]*Container

Types

type Container

type Container struct {
	PodName            string
	Namespace          string
	Name               string
	PodUID             string
	UID                string
	InitContainer      bool
	State              *corev1.ContainerState
	LoggregatorOptions config.LoggregatorOptions
	Loggregator        *Loggregator
	AppMeta            *LoggregatorAppMeta
}

func (*Container) Read

func (c *Container) Read(ctx context.Context, LoggregatorOptions config.LoggregatorOptions, KubeConfig *rest.Config, wg *sync.WaitGroup)

func (*Container) Tail

func (c *Container) Tail(kubeClient *kubernetes.Clientset) error

Tail connects to the Kube

type ContainerList

type ContainerList struct {
	Containers         map[string]*Container
	KubeConfig         *rest.Config
	LoggregatorOptions config.LoggregatorOptions
	Tails              sync.WaitGroup
	Context            context.Context
}

func (*ContainerList) AddContainer

func (cl *ContainerList) AddContainer(c *Container)

func (ContainerList) EnsureContainer

func (cl ContainerList) EnsureContainer(c *Container) error

EnsureContainer make sure the container exists in the list and we are monitoring it.

func (*ContainerList) EnsurePodStatus

func (cl *ContainerList) EnsurePodStatus(pod *corev1.Pod) error

EnsurePodStatus handles a pod event by adding or removing container tailing goroutines. Every running container in the monitored namespace has its own goroutine that reads its log stream. When a container is stopped we stop the relevant gorouting (if it is still running, it could already be stopped because of an error).

func (*ContainerList) GetContainer

func (cl *ContainerList) GetContainer(uid string) (*Container, bool)

func (*ContainerList) RemoveContainer

func (cl *ContainerList) RemoveContainer(uid string) error

func (*ContainerList) UpdateContainer

func (cl *ContainerList) UpdateContainer(c *Container) error

UpdateContainer decides whether a container should be added, left alone or removed from the container list. It does that but checking the state of of the container.

type Extension

type Extension struct {
	Logger  *zap.SugaredLogger
	Options GraceOptions
}

Extension changes pod definitions

func NewGracePeriodInjector

func NewGracePeriodInjector(opts *GraceOptions) *Extension

NewGracePeriodInjector returns the podwatcher extension which injects a grace Period on Eirini generated pods

func (*Extension) Handle

func (ext *Extension) Handle(ctx context.Context, eiriniManager eirinix.Manager, pod *corev1.Pod, req admission.Request) admission.Response

Handle injects gracefulPeriod in opi containers: In case an application is too fast to fail, we might miss logs as Kubernetes will terminate the container before the watcher had occasion to attach to stream any logs.

  • Finalizers let the pod terminates, not giving any chance to get logs from terminated container.
  • PostStop/PreStart hooks doesn't guarantee execution in case of containers terminated by failures (e.g. an invalid app was pushed in Eirini), if causing crashloopbackoff hooks aren't executed correctly.

type GraceOptions

type GraceOptions struct {
	FailGracePeriod, SuccessGracePeriod string

	StagingDownloaderEntrypoint string
	StagingExecutorEntrypoint   string
	StagingUploaderEntrypoint   string
	RuntimeEntrypoint           string

	GraceImageContainsString string
}

GraceOptions lets customize the graceful periods and the entrypoint of the images which are mutated to inject the grace period logic

type Loggregator

type Loggregator struct {
	Meta              *LoggregatorAppMeta
	ConnectionOptions config.LoggregatorOptions
	KubeClient        *kubernetes.Clientset
	LoggregatorClient *loggregator.IngressClient
	Context           context.Context
}

func NewLoggregator

func NewLoggregator(ctx context.Context, m *LoggregatorAppMeta, kubeClient *kubernetes.Clientset, connectionOptions config.LoggregatorOptions) *Loggregator

func (*Loggregator) Envelope

func (l *Loggregator) Envelope(message []byte) *loggregator_v2.Envelope

func (*Loggregator) SetupLoggregatorClient

func (l *Loggregator) SetupLoggregatorClient() error

func (*Loggregator) Tail

func (l *Loggregator) Tail(namespace, pod, container string) error

func (*Loggregator) Write

func (l *Loggregator) Write(b []byte) (int, error)

type LoggregatorAppMeta

type LoggregatorAppMeta struct {
	SourceID, InstanceID                               string
	SourceType, PodName, Namespace, Container, Cluster string // Custom tags
}

type LoggregatorLogger

type LoggregatorLogger struct{}

func (LoggregatorLogger) Panicf

func (LoggregatorLogger) Panicf(message string, args ...interface{})

func (LoggregatorLogger) Printf

func (LoggregatorLogger) Printf(message string, args ...interface{})

type PodWatcher

type PodWatcher struct {
	Config     config.ConfigType
	Containers ContainerList
	Manager    eirinix.Manager
}

func NewPodWatcher

func NewPodWatcher(config config.ConfigType) *PodWatcher

func (*PodWatcher) EnsureLogStream

func (pw *PodWatcher) EnsureLogStream(ctx context.Context, manager eirinix.Manager) error

EnsureLogStream ensures that the already running pod logs are tracked and sets the latest RV found to be able to track future changes. It gets the current RV to start watching on and reads the pods currently running in the namespace to process them with EnsurePodStatus. This allows the PodWatcher to stream logs of currently running pods if restarted (or updated).

func (*PodWatcher) Finish

func (pw *PodWatcher) Finish()

func (*PodWatcher) Handle

func (pw *PodWatcher) Handle(manager eirinix.Manager, e watch.Event)

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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