k8swatcher

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrResultsClosed = errors.New("k8s result channel closed")

ErrResultsClosed indicates that the function exited because the results channel was closed.

Functions

func InitKubernetesExtraClusterClient

func InitKubernetesExtraClusterClient(configPath, context string) (kubernetes.Interface, error)

InitKubernetesExtraClusterClient attempts to initialize a kubernetes client outside the cluster

func InitKubernetesInClusterClient

func InitKubernetesInClusterClient() (kubernetes.Interface, error)

InitKubernetesInClusterClient initializes a kubernetes clientset with the config that service account kubernetes gives to pods. Assumes the application is running in a kubernetes cluster and will return an error when not running in cluster

Types

type CreatePod

type CreatePod struct {
	IP *net.IPAddr
	// The new Pod's definition
	Def *k8score.Pod
	// contains filtered or unexported fields
}

CreatePod indicates that a pod has been created and now has an assigned IP

func (*CreatePod) Continues added in v1.0.0

func (c *CreatePod) Continues() bool

Continues indicates that the next event will use the same ResourceVersion because this event is part of either the same initial-state-dump or resync.

func (*CreatePod) PodName

func (c *CreatePod) PodName() string

PodName implements PodEvent

func (*CreatePod) ResourceVersion added in v0.2.0

func (c *CreatePod) ResourceVersion() ResourceVersion

ResourceVersion implements PodEvent

type DeletePod

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

DeletePod indicates that a pod has been destroyed (or is shutting down) and should no longer be watched.

func (*DeletePod) Continues added in v1.0.0

func (d *DeletePod) Continues() bool

Continues indicates that the next event will use the same ResourceVersion because this event is part of the same resync.

func (*DeletePod) PodName

func (d *DeletePod) PodName() string

PodName implements PodEvent

func (*DeletePod) ResourceVersion added in v0.2.0

func (d *DeletePod) ResourceVersion() ResourceVersion

ResourceVersion implements PodEvent

type EventCallback

type EventCallback func(context.Context, PodEvent)

EventCallback defines a function for handling pod lifetime events the context will be a copy of the context passed to the Run() method on PodWatcher.

type InitialListComplete added in v1.1.0

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

InitialListComplete is a synthetic event indicating that the initial list of pods matching the specified label matcher is complete (all previous `CreatePod` events' callbacks have completed).

func (*InitialListComplete) Continues added in v1.1.0

func (i *InitialListComplete) Continues() bool

Continues indicates that the next event will use the same ResourceVersion because this event is part of either the same initial-state-dump or resync. This is always the last event of the initial state-dump, so it always has Continues set to false.

func (*InitialListComplete) PodName added in v1.1.0

func (i *InitialListComplete) PodName() string

PodName returns an empty string because it's not really a single pod event.

func (*InitialListComplete) ResourceVersion added in v1.1.0

func (i *InitialListComplete) ResourceVersion() ResourceVersion

ResourceVersion returns the ResourceVersion of the initial list

type Logger

type Logger interface {
	Printf(string, ...interface{})
}

Logger implementations resemble the stdlogger interface.

type ModPod

type ModPod struct {
	IP *net.IPAddr
	// The new Pod definition
	Def *k8score.Pod
	// contains filtered or unexported fields
}

ModPod indicates a change in a pod's status or definition (anything that isn't a creation or deletion)

func (*ModPod) Continues added in v1.0.0

func (m *ModPod) Continues() bool

Continues indicates that the next event will use the same ResourceVersion because this event is part of either the same initial-state-dump or resync.

func (*ModPod) PodName

func (m *ModPod) PodName() string

PodName implements PodEvent

func (*ModPod) ResourceVersion added in v0.2.0

func (m *ModPod) ResourceVersion() ResourceVersion

ResourceVersion implements PodEvent

type PodEvent

type PodEvent interface {
	PodName() string
	ResourceVersion() ResourceVersion
	// Continues indicates that the next event will use the same
	// ResourceVersion because this event is part of either the same
	// initial-state-dump or resync.
	Continues() bool
}

PodEvent is the interface type for events being returned over a channel

type PodWatcher

type PodWatcher struct {

	// Logger is a Logger implementation which is used for logging if non-nil
	Logger Logger
	// contains filtered or unexported fields
}

PodWatcher uses the k8s API to watch for new/deleted k8s pods

func NewPodWatcher

func NewPodWatcher(cs kubernetes.Interface, k8sNamespace, selector string, cbs ...EventCallback) *PodWatcher

NewPodWatcher constructs a new PodWatcher. Each callback in the variadic callback list is called in its own goroutine.

func (*PodWatcher) Run

func (p *PodWatcher) Run(ctx context.Context) error

Run starts a watcher loop, will generate CreatePod events for all existing pods at startup (those callbacks are run inband, so don't do anything expensive in them).

type ResourceVersion added in v0.2.0

type ResourceVersion string

ResourceVersion is the version string associated with the object/event. K8s documents that it is only valid to compare it for equality, and hence not otherwise sortable.

Jump to

Keyboard shortcuts

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