kubernetes

package
v0.0.0-...-1ec7dca Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxGracePeriod   time.Duration = 8 * time.Minute
	DefaultEvictionOverhead time.Duration = 30 * time.Second
)

Default pod eviction settings.

View Source
const Component = "draino"

Component is the name of this application.

View Source
const (
	// DefaultDrainBuffer is the default minimum time between node drains.
	DefaultDrainBuffer = 10 * time.Minute
)

Variables

View Source
var (
	MeasureNodesCordoned = stats.Int64("draino/nodes_cordoned", "Number of nodes cordoned.", stats.UnitDimensionless)
	MeasureNodesDrained  = stats.Int64("draino/nodes_drained", "Number of nodes drained.", stats.UnitDimensionless)

	TagNodeName, _ = tag.NewKey("node_name")
	TagResult, _   = tag.NewKey("result")
)

Opencensus measurements.

Functions

func BuildConfigFromFlags

func BuildConfigFromFlags(apiserver, kubecfg string) (*rest.Config, error)

BuildConfigFromFlags is clientcmd.BuildConfigFromFlags with no annoying dependencies on glog. https://godoc.org/k8s.io/client-go/tools/clientcmd#BuildConfigFromFlags

func IsTimeout

func IsTimeout(err error) bool

IsTimeout returns true if the supplied error was caused by a timeout.

func LocalStoragePodFilter

func LocalStoragePodFilter(p core.Pod) (bool, error)

LocalStoragePodFilter returns true if the supplied pod does not have local storage, i.e. does not use any 'empty dir' volumes.

func MirrorPodFilter

func MirrorPodFilter(p core.Pod) (bool, error)

MirrorPodFilter returns true if the supplied pod is not a mirror pod, i.e. a pod created by a manifest on the node rather than the API server.

func NewEventRecorder

func NewEventRecorder(c kubernetes.Interface) record.EventRecorder

NewEventRecorder returns a new record.EventRecorder for the given client.

func NewNodeConditionFilter

func NewNodeConditionFilter(ct []string) func(o interface{}) bool

NewNodeConditionFilter returns a filter that returns true if the supplied object is a node with any of the supplied node conditions.

func NewNodeLabelFilter

func NewNodeLabelFilter(labels map[string]string) func(o interface{}) bool

NewNodeLabelFilter returns a filter that returns true if the supplied object is a node with all of the supplied labels.

func NodeSchedulableFilter

func NodeSchedulableFilter(o interface{}) bool

NodeSchedulableFilter returns true if the supplied object is a schedulable node.

func UnreplicatedPodFilter

func UnreplicatedPodFilter(p core.Pod) (bool, error)

UnreplicatedPodFilter returns true if the pod is replicated, i.e. is managed by a controller (deployment, daemonset, statefulset, etc) of some sort.

Types

type APICordonDrainer

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

APICordonDrainer drains Kubernetes nodes via the Kubernetes API.

func NewAPICordonDrainer

func NewAPICordonDrainer(c kubernetes.Interface, ao ...APICordonDrainerOption) *APICordonDrainer

NewAPICordonDrainer returns a CordonDrainer that cordons and drains nodes via the Kubernetes API.

func (*APICordonDrainer) Cordon

func (d *APICordonDrainer) Cordon(n *core.Node) error

Cordon the supplied node. Marks it unschedulable for new pods.

func (*APICordonDrainer) Drain

func (d *APICordonDrainer) Drain(n *core.Node) error

Drain the supplied node. Evicts the node of all but mirror and DaemonSet pods.

type APICordonDrainerOption

type APICordonDrainerOption func(d *APICordonDrainer)

APICordonDrainerOption configures an APICordonDrainer.

func EvictionHeadroom

func EvictionHeadroom(h time.Duration) APICordonDrainerOption

EvictionHeadroom configures an amount of time to wait in addition to the MaxGracePeriod for the API server to report a pod deleted.

func MaxGracePeriod

func MaxGracePeriod(m time.Duration) APICordonDrainerOption

MaxGracePeriod configures the maximum time to wait for a pod eviction. Pod containers will be allowed this much time to shutdown once they receive a SIGTERM before they are sent a SIGKILL.

func WithPodFilter

func WithPodFilter(f PodFilterFunc) APICordonDrainerOption

WithPodFilter configures a filter that may be used to exclude certain pods from eviction when draining.

type CordonDrainer

type CordonDrainer interface {
	Cordoner
	Drainer
}

A CordonDrainer both cordons and drains nodes!

type Cordoner

type Cordoner interface {
	// Cordon the supplied node. Marks it unschedulable for new pods.
	Cordon(n *core.Node) error
}

A Cordoner cordons nodes.

type Drainer

type Drainer interface {
	// Drain the supplied node. Evicts the node of all but mirror and DaemonSet pods.
	Drain(n *core.Node) error
}

A Drainer drains nodes.

type DrainingResourceEventHandler

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

A DrainingResourceEventHandler cordons and drains any added or updated nodes.

func NewDrainingResourceEventHandler

NewDrainingResourceEventHandler returns a new DrainingResourceEventHandler.

func (*DrainingResourceEventHandler) OnAdd

func (h *DrainingResourceEventHandler) OnAdd(obj interface{})

OnAdd cordons and drains the added node.

func (*DrainingResourceEventHandler) OnDelete

func (h *DrainingResourceEventHandler) OnDelete(_ interface{})

OnDelete does nothing. There's no point cordoning or draining deleted nodes.

func (*DrainingResourceEventHandler) OnUpdate

func (h *DrainingResourceEventHandler) OnUpdate(_, newObj interface{})

OnUpdate cordons and drains the updated node.

type DrainingResourceEventHandlerOption

type DrainingResourceEventHandlerOption func(d *DrainingResourceEventHandler)

DrainingResourceEventHandlerOption configures an DrainingResourceEventHandler.

func WithDrainBuffer

WithDrainBuffer configures the minimum time between scheduled drains.

func WithLogger

WithLogger configures a DrainingResourceEventHandler to use the supplied logger.

type NodeProcessed

type NodeProcessed map[types.UID]bool

NodeProcessed tracks whether nodes have been processed before using a map.

func NewNodeProcessed

func NewNodeProcessed() NodeProcessed

NewNodeProcessed returns a new node processed filter.

func (NodeProcessed) Filter

func (processed NodeProcessed) Filter(o interface{}) bool

Filter returns true if the supplied object is a node that this filter has not seen before. It is not threadsafe and should always be the last filter applied.

type NodeStore

type NodeStore interface {
	// Get an node by name. Returns an error if the node does not exist.
	Get(name string) (*core.Node, error)
}

An NodeStore is a cache of node resources.

type NodeWatch

type NodeWatch struct {
	cache.SharedInformer
}

An NodeWatch is a cache of node resources that notifies registered handlers when its contents change.

func NewNodeWatch

NewNodeWatch creates a watch on node resources. Nodes are cached and the provided ResourceEventHandlers are called when the cache changes.

func (*NodeWatch) Get

func (w *NodeWatch) Get(name string) (*core.Node, error)

Get an node by name. Returns an error if the node does not exist.

type NoopCordonDrainer

type NoopCordonDrainer struct{}

A NoopCordonDrainer does nothing.

func (*NoopCordonDrainer) Cordon

func (d *NoopCordonDrainer) Cordon(n *core.Node) error

Cordon does nothing.

func (*NoopCordonDrainer) Drain

func (d *NoopCordonDrainer) Drain(n *core.Node) error

Drain does nothing.

type PodFilterFunc

type PodFilterFunc func(p core.Pod) (bool, error)

A PodFilterFunc returns true if the supplied pod passes the filter.

func NewDaemonSetPodFilter

func NewDaemonSetPodFilter(client kubernetes.Interface) PodFilterFunc

NewDaemonSetPodFilter returns a FilterFunc that returns true if the supplied pod is not managed by an extant DaemonSet.

func NewPodFilters

func NewPodFilters(filters ...PodFilterFunc) PodFilterFunc

NewPodFilters returns a FilterFunc that returns true if all of the supplied FilterFuncs return true.

Jump to

Keyboard shortcuts

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